views:

884

answers:

5

Windows API ::FindWindow function fails when called from Service application. GetLastError() also returns 0 (success?). Is this some privilege\access right problem? Do you think it's design problem and I should use another IPC method?

+3  A: 

Have you enabled 'Desktop Integration' with your service?

leppie
That feature is no longer available starting with Vista.
Remy Lebeau - TeamB
A: 

No. How can I do it?

bgee
AFAIK, this not available on Vista, but previous OS versions it lives in the properties of the service in the Services control panel.
leppie
+4  A: 

leppie's right, Windows services are usually denied in interaction with desktop. You can bypass that in XP and earlier versions but won't be able to do in Vista and above. You'd better delegate desktop and user interactions to a GUI application. See this document for details.

Claymore
+1  A: 

Services run in Session 0. On XP and earlier, the first user to log in also runs in Session 0, and subsequent users run in Sessions 1 and higher. If the service is set to "Interact with the Desktop", then it can access any user windows running in Session 0. However, starting with Vista, users never run in Session 0 anymore. FindWindow() only works in the context of the Session it is called in, as windows cannot be accessed across Session boundaries.

Remy Lebeau - TeamB
A: 

I too got impacted by the same problem. Earlier one of my service use to do a FindWindow. Now to get the FindWindow functionality in Service should i write a separate helper EXE and invoke it with CreateProcessAsUser?

coolcake