3

我正在创建一个信号量:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
try
{
    bool createdNew;
    System.Security.AccessControl.SemaphoreSecurity semaphoreSecurity = new System.Security.AccessControl.SemaphoreSecurity();
    semaphoreSecurity.SetAccessRule(new System.Security.AccessControl.SemaphoreAccessRule(sid, System.Security.AccessControl.SemaphoreRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
    this.semaphore = new Semaphore(1, 1, semaphoreName, out createdNew, semaphoreSecurity);
    if (!this.semaphore.WaitOne(timeoutInMilliSeconds))
        throw new TimeoutException("Timeout while waiting " + semaphoreName + " semaphore (" + timeoutInMilliSeconds + " ms)");
}
catch (System.UnauthorizedAccessException e)
{
    this.semaphore = null;
    throw new UnauthorizedAccessException("Semaphore '" + semaphoreName + "'. " + e.Message);
}
catch
{
    this.semaphore = null;
    throw;
}

并且在 Semaphore 构造函数中有 UnauthorizedAccessException 和下一条消息:

信号量'Global\Program.Req.Sem'。拒绝访问端口”

怎么了?如何解决?

附加信息:我猜它只发生在非管理员用户身上,即使他们是“管理员”组的成员。

4

0 回答 0