[python-win32] Interacting with the desktop as a service onVista

Steven James steven.james at gmail.com
Wed Oct 22 19:35:43 CEST 2008


I don't know if this will help, but have you seen this article?

http://msdn.microsoft.com/en-us/library/ms683502.aspx

It says that services cannot interact with desktop users as of Windows
Vista. I guess that's the official word.

As with all issues, however, there are ways around it. This is a hack I
heard about somewhere...can't find much better than some silly VB code for
it right now. The basic idea is to create a "Scheduled Task" that has no
schedule (so it won't run). You can then manually call the Scheduled Task
from your service.

Dim server
Dim user
Dim password
Dim domain
Dim taskObj
server   = "sqe-18"
user     = "MyAdminUser"
password = "MyAdminPassword"
domain   = "MyDomain"
Set service = CreateObject("Schedule.Service")
service.Connect server,user,domain,password
Set rootFolder = service.GetFolder("\")
Set colTasks = rootFolder.GetTasks(0)
For Each task In colTasks
    If (StrComp(task.Name,"RunFooEXE",1) = 0) Then
        Set taskObj = task.Run("")
    End If
Next

The VB code can even be used to create the task and run it on a remote
computer (assuming you have proper credentials, etc).

Does this help? Sorry I don't have the knowledge to quickly translate this
into python/win32, but it should be pretty close already.


Steven James


On Wed, Oct 22, 2008 at 1:07 PM, Matt Herbert (matherbe) <matherbe at cisco.com
> wrote:

>
> > -----Original Message-----
> > From: python-win32-bounces+matherbe=cisco.com at python.org
> > [mailto:python-win32-bounces+matherbe <python-win32-bounces%2Bmatherbe>=
> cisco.com at python.org]
> > On Behalf Of Tim Golden
> > Sent: Wednesday, October 22, 2008 10:21 AM
> > Cc: python-win32 at python.org
> > Subject: Re: [python-win32] Interacting with the desktop as a
> > service onVista
> >
> > Matt Herbert (matherbe) wrote:
> > > So I have a service that needs to interact with the desktop
> > on a Vista
> > > machine. I've read multiple articles about Vista's updated security
> > > and it's restrictions on services. So I realize that in
> > order for the
> > > service to interact with desktop, I'm going to need to create a new
> > > process as a "normal" user, and use some form of IPC
> > between the child
> > > process and my service to get at the information I need.
> >
> >
> > Without knowing what the exact problem which you're
> > encountering, it seems to me that you're probably fighting
> > the system. I don't use Vista myself but I seem to remember
> > that the Service security subsystem has been beefed up to
> > make things like this even harder.
> >
> > You don't say exactly what your interaction with the desktop
> > is. Can you not do the usual thing of having a user run a
> > (possibly systray-ed) app in his userspace which comminicates
> > with your service via, say, named pipes (or sockets, or whatever)?
> >
> >
> > Can you come across with more information, such as how your
> > service will be interacting with the desktop?
> >
> > TJG
>
> Apologies,
>
> I had thought I had provided enough information, but after re-reading my
> post, I realized I wasn't really describing the problem very well.
>
> My situation is I have a python service which runs 24/7. Occasionally
> The service needs to access windows on the desktop. That is, it needs to
> enumerate all the windows, find a specific pop-up, and press a button.
> Now, this was not a problem on XP, but the new service restrictions on
> vista make it impossible for the Service to access the windows on the
> interactive desktop (winsta0\default). So I've written a module that
> runs a simple socket server, which tries to CreateProcessAsUser on a
> small short lived python script, which will do the work on the desktop.
> When the child process starts up, it connects back to the service, and
> waits for commands.
>
> Now the problem: From the service (running as the SYSTEM user), I use
> the CreateProccessAsUser function, to start up my child process as the
> user 'joe' (who, incidentally, is also logged in to the desktop). The
> process seems to startup without any problems and even runs as the user
> 'joe'. However, the child process still is not able to access the
> windows on the desktop.
>
> This is what lead me to the MSDN example (in my original post). In the
> CreateProcessAsUser documentation
> (http://msdn.microsoft.com/en-us/library/ms682429.aspx), under the
> remarks section, it discusses the requirements for the child process to
> have permissions to interact with desktop. It states that the DACL's of
> the windows station and the desktop must be updated to grant access to
> the user represented by the token (acquired via the LogonUser function).
> So I've done all that, and still I cannot get my child process onto the
> interactive desktop.
>
> FWIW, the child process is short lived and I would prefer to not have to
> start it up by other means. I really want the service to start the child
> process.
>
> Any Ideas?
>
> Thanks
> -Matt
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081022/4a81b45d/attachment-0001.htm>


More information about the python-win32 mailing list