Service interact with desktop. Desktop change. How to manage desktop changes?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello.
This scenario needs to run under XP SP3 and Vista+
I have a service that runs under local system.
I have a Helper application that the service starts<br/>
via CreateProcessAsUser(). the helper is started under<br/>
the current desktop.
The helper interacts with the desktop and communicates with <br/>
the service via IPC.
The helper is running a thread that watches to see if the <br/>
current desktop changes (OpenInputDesktop). If the helper sees <br/>
the desktop change it shuts down.
The service sees the helper shut down and starts another instance of the <br/>
helper application (which is started under the new/current desktop).
This all works fine and dandy when the service is started manually.<br/>
This does not work when the service is started automatically<br/>
(I assume when my service fires up the helper there is not a desktop yet).
I am looking for a way to change my watch for desktop changes and to get<br/>
the service to fire up the helper initially only when a desktop is available.
1.) Have service manage helper instances:
It would be nice to have the service manage the shutting down and starting<br/>
of a new instance of the helper on its own (NOT have the helper watching for<br/>
desktop changes), but I have been unable to get this to work.
I understand (I think!) all about the ServiceControlHandler() <br/>
SERVICE_CONTROL_SESSIONCHANGE but this does not allow me to get<br/>
notified when the active desktop changes (like Secure Desktop UAC prompts Vista+).
I am unable to figure out a way for the service to watch the current active desktop,<br/>
or even find out if there is a current active desktop running. Since it is a service
<br/>
(Vista+) it does not have access to the desktop so OpenInputDesktop() always fails.
2.) Service starting automatically.
As I stated earlier my service starts the helper application. This fails (when startup<br/>
is set to automatic) because there is no active desktop (yet) when my service tries to
<br/>
start the helper application.
I understand service dependencies, but what I really need to know is that their<br/>
actually is an active desktop before I fire up the helper.
Any help greatly appreciated.


View the full article
 
Back
Top