我是C ++的新手......我的CreateEvent工作正常:
HANDLE result = CreateEvent(NULL, // No security.
TRUE, // Manual-reset event.
FALSE, // Not signaled.
L"Global\\MyResetEvent"); // Event name.
但我如何处理安全属性以在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);
答案 0 :(得分:1)
我认为应该这样做,最后,感谢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");