Broadcasting a message/event from a service (to all Windows sessions)
The Windows Device Management functions "provide a way to uniformly notify all applications and system components of changes that may affect their operation or access to resources".
I have a service that needs to provide notifications of certain events to any interested applications and services. This API looks like a perfect fit, because interested applications/services can elect to receive the broadcasts with RegisterDeviceNotification() and the sender doesn't have to keep a list of clients.
The DBT_CUSTOMEVENT
event type seemed to be the right one to use, but that can be sent only by kernel mode drivers. Fortunately there is a DBT_USERDEFINED
. The documentation says this should be sent using BroadcastSystemMessage()
.
But then a colleague reminded me of "session zero isolation" in Windows Vista. Will BroadcastSystemMessage()
of a WM_DEVICECHANGE
be able to reach applications running in all sessions, as well as other services?
It looks like the question doesn't arise for kernel drivers because they use a different function to send the message. But my notifications orig开发者_StackOverflow中文版inate in a service, not a kernel driver.
Am I barking up the wrong tree? I know I could use named pipes, but I really want a broadcast mechanism to keep things as simple as possible. I don't want the service that originates the messages to have to worry about where they are going. I also want to avoid third-party libraries. I want to do this the proper Microsoft-Approved Way and not re-invent the wheel.
According to the documentation for BroadcastSystemMessage()
you can include the BSM_ALLDESKTOPS
flag which looks like it will be needed for what you desire. It requires the SE_TCB_NAME
privilege.
精彩评论