2008-12-19 78 views
7

我們創建Mutex的方式存在問題。這個問題行是:非英語操作系統中Everyone組的名稱

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

硬編碼的「所有人」串僅適用於英文的操作系統,我們如何改變此行,它適用於所有的語言嗎?

回答

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) 
3

我有同樣的問題,但需要「Everyone」組名稱的實際本地化字符串才能啓用訪問MessageQueue。這是我找到的解決方案,它工作正常:

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