I have created a windows service to run my custom application with createProcessAsUser. The result is one application running with SYSTEM user in session Id 0 as I expect. My problem is, I need to have some communication between this application an others created by the current user.

If some desktop events happenned (SC_SCREENSAVE, monitor off), events caught by current user apps, I need to tell that to my SYSTEM application. I have used:

SendMessage(HWND_BROADCAST, CURRENT_USER_HAS_DONE_SOMETHING, 0, 0);

Even the SYSTEM application catch a lot of system events (suspend, logoff...), and is running in the same session Id, my custom messages are never caught. It seems like Sendmessage don't work for SYSTEM user.

How can I send a message from user current session to a SYSTEM application?

有帮助吗?

解决方案

Another option is to use the old ControlService function along with a user-defined control code. It is not appropriate for complicated communication (you can't pass any parameters to the service) but it works well for the simple "something-happened" notifications you outlined.

其他提示

Obviously broadcasting messages isn't the correct solution. A nicer solution is probably CreateEventEx. This creates a named event. Your regular app can then call SetEvent and the SYSTEM app can wait on this event.

Recent versions of Windows don't allow exchanging messages between session 0 and desktop sessions. This is called Session 0 isolation.

You can find more info here and here.

Usual alternatives are TCP/IP, pipes, remoting, etc, which are described in this SO answer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top