views:

628

answers:

1

I have to write a Windows Service application (no GUI) that will monitor an event, and if it occurs will send a standard windows message to an application. The handle of the application will be given to the service by a DLL which is then unloaded, so a windows message is the way we wish to use.

The question though is whether the service needs to do anything special to use SendMessage to the window handle, given that it might be on a different screen or something in Vista. Is this possible, and if so, what do I have to do please?

+4  A: 

User Interface Privilege Isolation (UIPI):

Microsoft Windows Vista and later. Message sending is subject to User Interface Privilege Isolation (UIPI). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.

Source

You can read about User Interface Privilege Isolation (UIPI) here.

To get around this you can set uiAccess to true in your manifest file. You also have to make sure your application is signed using authenticode with a certificate from a signing authority such as verisign. This can get pretty expensive.


Session 0 isolation:

It is also my belief that you can't call SendMessage across sessions. So if you have a service running in session 0 you need to find another means to communicate with your process that would be running in a session > 0. Example: via pipe.

In Windows Vista, Windows 2008 Server and later all services run in session 0, and all applications that you start run in session > 0. This is called session 0 isolation. Here is a good document that has information all about session 0 isolation.

If you don't have access to the source of the program you want to send messages to, you could get around this by making an application that communicates with your service and acts as a proxy to relay the message to the application in its same session.


Ovearll:

If you develop your application on pre-Vista and it works fine. There is a very high chance it will be broken in Vista.

Brian R. Bondy
Regardless if it's right or not, that's some good information.
toast
That sounds bad. Clarification: I don't know enough about the subject at hand to know whether this is helpful or not, but I feel that the information is generally useful so I gave it a +1.
toast
:) Thanks, I think the poster will have both of these problems. But I also don't have the exact details of his problem.
Brian R. Bondy
Thanks. I'll accept this answer - the problem needs to be solved in another way, so I'll ask a DLL question now!
mj2008