Reputation: 12912
I am fairly new to C++...I have the CreateEvent working okay with this code:
HANDLE result = CreateEvent(NULL, // No security.
TRUE, // Manual-reset event.
FALSE, // Not signaled.
L"Global\\MyResetEvent"); // Event name.
But what do I have to do with the security attributes to have an equivalent of the following in C#?
SecurityIdentifier localSystemUsers = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
SecurityIdentifier adminUsers = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
EventWaitHandleAccessRule localSystemRule = new EventWaitHandleAccessRule(localSystemUsers, EventWaitHandleRights.FullControl, AccessControlType.Allow);
EventWaitHandleAccessRule adminRule = new EventWaitHandleAccessRule(adminUsers, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);
EventWaitHandleSecurity security = new EventWaitHandleSecurity();
security.AddAccessRule(localSystemRule);
security.AddAccessRule(adminRule);
bool createdNew;
event = new EventWaitHandle(false, EventResetMode.ManualReset, MyEventName, out createdNew, security);
Upvotes: 0
Views: 571
Reputation: 12912
I think this should do it, in the end, thanks to this link:
TCHAR *szSD = TEXT("D:") // Discretionary ACL.
TEXT("(A;OICI;GA;;;BA)"); // Allow full control to administrators.
TEXT("(A;OICI;GA;;;SY)"); // Allow full control to the local system.
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;
ConvertStringSecurityDescriptorToSecurityDescriptor(szSD, SDDL_REVISION_1, &((&sa)->lpSecurityDescriptor), NULL);
HANDLE result = CreateEvent(&sa, TRUE, FALSE, L"Global\\CustomManualResetEvent");
Upvotes: 1