Can we create an Event(CreateEvent) in windows for both system session and user session using c++

checkingrandom 206 Reputation points
2022-06-22T11:10:25.323+00:00

If we create a event using CreateEvent in windows in system session, we cannot able to open that event in USER session using OpenEvent.

Is there any way of creating a global event so that both the user and system can open it and close (CloseHandle) anywhere.

Example:
I'm creating a event in system session(Service) but then I'm impersonating to User so after impersonation I cant able to close the event handle, because the both sessions are different.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

Accepted answer
  1. RLWA32 43,306 Reputation points
    2022-06-22T11:52:24.803+00:00

    Windows services create events in the global namespace as @David Lowndes pointed out. However, in order for a process running in a standard user's interactive session to open a named event created by a service in the global namespace using the "Global\" prefix the event must have a security descriptor that grants access to the user account or one of the groups to which the user account belongs.

    Example code at Modifying the ACLs of an Object in C++ shows how to accomplish this by modifying the security descriptor for an object after it is created. Of course you would need to provide the specifics for an event object when adapting the example code.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful