2012-08-06 39 views
4

在我的C#代碼中,我想將用戶添加到「管理員」組。我聽說在德語版本的Windows上,該組將稱爲「管理員」,也許在其他本地版本中會有其他名稱。如何以獨立於區域的方式查找本地組?

var context = new PrincipalContext(ContextType.Machine); 
var group = GroupPrincipal.FindByIdentity(context, "Administrators"); 

,因此這將打破,如果羣實際上有一些其他的名字:做搜索時

我的代碼傳遞一個硬編碼字符串。我發現this MSDN article with well-known SIDs堅果我不知道如何實際使用它們來解決我的問題。

如何找到獨立於Windows操作系統語言的本地組?

回答

4

我不知道這是否有幫助。

using System.Security; 
using System.Security.Principal; 

...... 
SecurityIdentifier sid = new SecurityIdentifier("S-1-5-32-544"); 
string name = sid.Translate(typeof(NTAccount)).Value; 
Console.WriteLine(name); 

結果是

"BUILTIN\Administrators" 

我已經採取了SID從this page在這裏你可以找到其他值進行試驗。

相關問題