7
我们创建Mutex
的方式存在问题。这个问题行是:非英语操作系统中Everyone组的名称
MutexAccessRule rule = new MutexAccessRule("Everyone", MutexRights.FullControl, AccessControlType.Allow);
硬编码的“所有人”串仅适用于英文的操作系统,我们如何改变此行,它适用于所有的语言吗?
我们创建Mutex
的方式存在问题。这个问题行是:非英语操作系统中Everyone组的名称
MutexAccessRule rule = new MutexAccessRule("Everyone", MutexRights.FullControl, AccessControlType.Allow);
硬编码的“所有人”串仅适用于英文的操作系统,我们如何改变此行,它适用于所有的语言吗?
谷歌今天是有帮助的:
这段代码解决了这个问题:
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
MutexAccessRule rule = new MutexAccessRule(sid, MutexRights.FullControl, AccessControlType.Allow);
VB:
Dim sid As System.Security.Principal.SecurityIdentifier = New System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, Nothing)
Dim rule As System.Security.AccessControl.MutexAccessRule = New System.Security.AccessControl.MutexAccessRule(sid, System.Security.AccessControl.MutexRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)
我有同样的问题,但需要“Everyone”组名称的实际本地化字符串才能启用访问MessageQueue。这是我找到的解决方案,它工作正常:
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var acct = sid.Translate(typeof(NTAccount)) as NTAccount;
myMessageQueue.SetPermissions(acct.ToString(), MessageQueueAccessRights.FullControl);