非英语操作系统中Everyone组的名称

时间:2008-12-19 22:51:44

标签: c# globalization

我们创建Mutex的方式存在问题。问题在于:

MutexAccessRule rule = new MutexAccessRule("Everyone", MutexRights.FullControl, AccessControlType.Allow);

硬编码的“Everyone”字符串仅适用于英语操作系统,我们如何更改此行以使其适用于所有语言?

2 个答案:

答案 0 :(得分:12)

谷歌今天有所帮助:

看起来像this will help

此代码解决了这个问题:

  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)

答案 1 :(得分:4)

我遇到了同样的问题,但需要“Everyone”组名的实际本地化字符串才能启用对MessageQueue的访问。这是我找到的解决方案,效果很好:

SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var acct = sid.Translate(typeof(NTAccount)) as NTAccount;
myMessageQueue.SetPermissions(acct.ToString(), MessageQueueAccessRights.FullControl);