0

我对 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);
4

1 回答 1

1

最后,我认为这应该做到这一点,这要归功于这个链接

    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");
于 2013-09-17T12:17:01.867 回答