I need to exchange data between a Windows service and a "regular" application.
To do that I use the shared memory (file mapping) and a couple of event.
I create the event objects in the service using "CreateEvent()" function and in the application I use the "OpenEvent()" function.
In the service:
HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, "Global\service_event");
In the application:
HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "Global\service_event");
The call in the service succedes successfully but the call in the application fails and gives a last error 5 = "access denied".
I have the same behavior if I execute the application "as administrator".
Can someone help me? Thanx
What is missing is the LPSECURITY_ATTRIBUTES that you specify in the first parameter of the CreateEvent. This controls who can access the event and what they can do with it.
With NULL as the first parameter, the event is created with with the default descriptor so that it is accessible to the system user only.
Here is an example of creating the SECURITY_ATTRIBUTES. It will allow full control of the event to Administrators. No error checking or resource cleanup included.