Wednesday, March 16, 2011

::FindWindow fails from Service application

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?

From stackoverflow
  • Have you enabled 'Desktop Integration' with your service?

    Remy Lebeau - TeamB : That feature is no longer available starting with Vista.
  • No. How can I do it?

    leppie : AFAIK, this not available on Vista, but previous OS versions it lives in the properties of the service in the Services control panel.
  • 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.

  • 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.

  • 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?

0 comments:

Post a Comment