Wednesday, October 13, 2010

CreateEvent Fails with Access Denied when Events with the Same Name from Different Applications.

So I tried to use my CreateEvent functions without name and it works. So why should I even bother to use a name ? I will Create Events without name from now on not to come across with this annoying problem again.
CreateEvent(NULL, FALSE , FALSE, NULL);//auto reset event
In my opinion unnamed events are not shared between processes. I.e. if you set an unnamed event in one application, then other processes will not see this change. Only threads that belong to the first process will detect the event.

Therefore, in case of multiple processes, you have to use named events.

In order to avoid your error, you can try a non-null first parameter of CreateEvent function:
SECURITY_DESCRIPTOR sd = { 0 };
::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
::SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);
SECURITY_ATTRIBUTES sa = { 0 };
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;

hEvent = ::CreateEvent(&sa, ..., _T("My event name")); // executed in each process
I hope this works.

No comments:

Post a Comment