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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.