0

Say, I have a Windows service application and also windowed client applications running in each logged on user session. If I call RegisterWindowMessage in each client app and try to trap that message there. And then also call RegisterWindowMessage with the same message name in the service app and then use it in a call to SendNotifyMessage again from the service to notify each client app of a single-fire event, will that work?

PS. I program using C++/MFC and native WinAPIs.

ahmd0
  • 16,633
  • 33
  • 137
  • 233

1 Answers1

1

If your service application is running under the system account it cannot send messages to the user account's application.

Your can try the following approach:

  • Go through all the sessions (WTSEnumerateSessions) to get all WindowStation,
  • Open these stations (OpenWindowStation),
  • Per station
    • Associate your process with the station (SetProcessWindowStation),
    • Go through all station desktops (Enumdesktops),
    • Go through all windows (EnumdesktopWindows) until your found one of your application's window

You probably will have issues with UAC though.

Flot2011
  • 4,601
  • 3
  • 44
  • 61
  • Thanks for your input. I just learned it the hard way by trying it out )) So, yeah, I can confirm that the above method would NOT work. I wish it was indicated in the documentation for that API... Oh well, I guess going back to global events. I wish they made it more easy to communicate between Windows services and user-mode processes... – ahmd0 Apr 18 '12 at 07:39
  • 1
    The way to communicate between a service and a user-mode process is for the user-mode process to connect to the service via [COM](http://msdn.microsoft.com/en-us/library/ms809975.aspx) or RPC. This is how the standard system services work. – Raymond Chen May 01 '12 at 13:55