.net 创建互斥时发生UnauthorizedAccessException

.net 创建互斥时发生UnauthorizedAccessException,.net,multithreading,winapi,mutex,.net,Multithreading,Winapi,Mutex,给定以下使用互斥锁的代码段: string mutexName = @"Global\MyMutex"; try { _mutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); } catch (WaitHandleCannotBeOpenedException) { SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnow

给定以下使用互斥锁的代码段:

string mutexName = @"Global\MyMutex";

try
{
    _mutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize);
}
catch (WaitHandleCannotBeOpenedException)
{
    SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
    MutexSecurity mutexSecurity = new MutexSecurity();
    mutexSecurity.AddAccessRule(new MutexAccessRule(securityIdentifier, MutexRights.Synchronize, AccessControlType.Allow));

    bool dummy = false;

    // Creates the internal Mutex without taking ownership on it.
    _mutex = new Mutex(false, mutexName, out dummy, mutexSecurity);
}
对于我的一些用户,当创建互斥时(在catch块中),会抛出UnauthorizedAccessException。我正在试图找到导致此异常的原因

信息是

对路径“Global\MyMutex”的访问被拒绝

我知道有些有问题的用户不是他们电脑的管理员。
我在MSDN上读过关于互斥和互斥AccessRule的内容,但我不清楚在哪里可以为给定用户分配或查看与互斥相关的权限。

我怀疑这不是互斥权限,而是在全局\命名空间(SeCreateGlobalPrivilege)中创建对象的权限


此外,如果此代码可以由多个进程同时调用,那么这里就有一个竞争条件。

对于SeCreateGlobalPrivilege,这非常有趣。在阅读了有关SeCreateGlobalPrivilege的内容后,我是错了还是无法在应用程序的运行时设置此权限?另一件事,这个特权似乎只适用于终端服务会话中不是管理员、本地系统帐户或服务帐户的用户?起初,我以为你在谈论线程竞赛,但事实上,你是对的。此代码用于进程间通信。因此,我需要解决流程问题。我应该如何保护代码不受此影响?