我对C++相当陌生...我让创建事件使用此代码正常工作:
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);
我认为这应该做到,最后,感谢这个链接:
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");