realnovice has asked for the wisdom of the Perl Monks concerning the following question:

    I have written a Perl application that does what it's supposed to do, in the background. It is running under the Local System context as an NT Service.

    The challenge is that when the service becomes active (ie. the condition that invokes the entire application), I would like it to "fork" another process under the context of the currently logged on "users", which would be "interactive" with their session.

    Kind of like AntiVirus.... it runs in the background as a Service with "GOD" rights to the system, but then spawns a Pop-UP to the users when a condition occurs.

Your wisdom is greatly appreciated!
- realnovice
  • Comment on Using Perl to write application to interact with users on Windows OS

Replies are listed 'Best First'.
Re: Using Perl to write application to interact with users on Windows OS
by BrowserUk (Patriarch) on Nov 29, 2004 at 13:58 UTC

    You probably need to take a look at Dave Roth's Win32::AdminMisc.

    In particular,

    CreateProcessAsUser($CommandString [, $DefaultDirectory] [, %Config]);

    To use that call, you would need to LogonAsUser(), which requires that you:

    1. Know who the current user is.
    2. Have the correct authentication to log on as them.

    None of which is discoverable by user 'LocalSystem'--by design. (Local System is actually quite a limited account deliberately!).

    An alternative, is to have the user install the service to run under their account. This can be specified when the service is installed, or modified (by the user) through the Control panel->Administrative tools->Services->Properties->Log On tab.

    On that same tab, you will also see a check box that offers the possibility for the a service that is "Logged on as 'Local System Account'" to "Allow service to interact with Desktop".

    When checked, the service process is created with a message thread which allows it to create GUI windows and dialogs to interact with the user--directly from the service process without the need to create a second process as some other user.

    Of course, it still only has LocalSystem permissions.


    Examine what is said, not who speaks.
    "But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
    "Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: Using Perl to write application to interact with users on Windows OS
by amrangaye (Friar) on Nov 29, 2004 at 13:42 UTC
    Hi
    I recently wrote something like this for Win XP. Mine was a token generation server that ran in the background, and only came up when the user needed a new token generated.
    You can do it very easily with the PerlTray app bundled with Activestate's Perl Dev kit. Simply write your app as a perltray application, and then add it to Window's startup folder (so it starts when windows does). It can run and do stuff in the background, and popup a Tk window when the used double-clicks on it.
Re: Using Perl to write application to interact with users on Windows OS
by elwarren (Priest) on Nov 29, 2004 at 19:21 UTC
    As long as you have security setup properly for your background service as BrowserUK points out, you can easily create a window using Win32::GUI. You create a window, add some controls (text and buttons) and some events, then make it visible. User clicks on message, maybe enters text, you set the window to hidden until you need it again.

    Depending on what your background process is doing, and how you're handling your event loop, forking a process for the gui component might be a good idea. You wouldn't want (but maybe you do) the gui to wait for input and stop the rest of your code from running. Win32::GUI has lots of examples, and there is some nice Win32::GUI code on this site as well.

    HTH