Python NT service SERVICE_INTERACTIVE_PROCESS

David Bolen db3l at fitlinxx.com
Wed Mar 26 11:15:35 EST 2003


llchen223 at hotmail.com (Lei Chen) writes:

> I'd like to create a GUI process (through CreateProcess) under a
> Python service.  Is this possible?  If so, how?  (snippets of code
> would be nice.) I would like to use the
> win32serviceutil.ServiceFramework class if this is doable.

If you don't mind defining your entire service as interactive, then
that's the simplest approach - I believe any child processes you start
should have access to the desktop as well.

To do this you'll need to change the CreateService call in
win32serviceutil.InstallService (or just write your own installation
function) to include the win32service.SERVICE_INTERACTIVE_PROCESS
flag.

If you don't want your service itself to have access to the desktop,
but only some of the processes it creates, it gets more complicated.
The winprocess.py demo included with win32all might provide a start
since it shows how to create a child process including with
authentication, but for a service you'll need to add code to grant
access to the default window station (winsta0) and desktop (default)
which is actually a reasonably complicated process involving access
lists.  The sequence proceeds something like (I'm not sure win32all
wraps all of these win32 functions or not):

    * Obtain the current process token either via LogonUser if newly
      authenticated or with OpenProcessToken.
    * Obtain the current process SID via GetTokenInformation.
    * Establish the default window station (typically "winsta0") with
      OpenWindowStation and SetProcessWindowStation
    * Establish the default desktop (typically "default") with
      OpenDesktop.
    * Add access control entries (ACE) to both the window station and
      desktop to permit the current process access (otherwise nothing
      will be displayed).  This itself is a complicated process with
      several API calls.

In the past, I've used MSDN article Q165194 as a basis for sample code
to accomplish a lot of this.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/




More information about the Python-list mailing list