上以标准用户身份创建信号量

上以标准用户身份创建信号量

本文介绍了无法在 Windows 7 上以标准用户身份创建信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是设计使然,但我似乎无法以标准用户或高级用户的身份在 Windows 7 上创建新的信号量.

I don't know if this is by design or not, but I cannot seem to create a new Semaphore on Windows 7 as a Standard User, or a Power User for that matter.

SemaphoreSecurity semSec = new SemaphoreSecurity();

// have also tried "Power Users", "Everyone", etc.
SemaphoreAccessRule rule = new SemaphoreAccessRule("Users", SemaphoreRights.FullControl, AccessControlType.Allow);

semSec.AddAccessRule(rule);

bool createdNew = false;

// throws exception
sem = new Semaphore(1, 1, SEMAPHORE_ID, out createdNew, semSec);

return true;

我收到 UnauthorizedAccessException 消息访问端口被拒绝."

I am receiving an UnauthorizedAccessException with the message "Access to the port is denied."

这可能吗?

推荐答案

经过更多的研究和尝试,我终于解决了这个问题,

After some more research and trying things out I finally solved this,

关键是在信号量名称前加上Global\",即

The key is to prepend "Global\" to the semaphore name, ie,

    const string NAME = "Global\\MySemaphore";

谢谢.

这篇关于无法在 Windows 7 上以标准用户身份创建信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:43