我的环境:
问题:
用户 U1 通过 RDP 连接到 Windows Server 并创建全局互斥体 (CreateMutex 带有 Global\ 前缀)
用户 U2 通过 RDP 连接到 Windows Server 并尝试获取 全局互斥体
U2 由于缺乏访问权限而失败(因为 U2 不是管理员,不是 一个系统,他也不是创造者)
我尝试通过为当前 AD 域用户添加一项权限来解决该问题,并且成功了。
这个解决方案足够安全吗?换句话说,授予访问权限以允许多个 RDP 用户访问互斥锁的正确方法是什么?
谢谢你
我将此代码用于远程桌面和互斥体。 MutexSecurity 对于访问其他 RDP 会话上已打开的互斥体是必需的。
var mSec = new System.Security.AccessControl.MutexSecurity();
// Add a rule that grants the current user the
// right to enter or release the mutex.
System.Security.Principal.SecurityIdentifier everyone = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
var rule = new System.Security.AccessControl.MutexAccessRule(everyone,
System.Security.AccessControl.MutexRights.Synchronize | System.Security.AccessControl.MutexRights.Modify,
System.Security.AccessControl.AccessControlType.Allow);
mSec.AddAccessRule(rule);
// Add a rule that denies the current user the
// right to change permissions on the mutex.
rule = new System.Security.AccessControl.MutexAccessRule(everyone,
System.Security.AccessControl.MutexRights.ChangePermissions,
System.Security.AccessControl.AccessControlType.Deny);
mSec.AddAccessRule(rule);
using (var mutex = new System.Threading.Mutex(false, $"Global\\AnDietzeMutex", out bool createdNew, mSec)); {
}