如何以独立于区域的方式查找本地组?

在我的C#代码中,我想将用户添加到“pipe理员”组。 我听说在德语版本的Windows上,这个组织将被称为“Administratoren”,也许在其他本地版本上会有其他名称。

我的代码在search时传递一个硬编码的string:

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

所以如果这个团体实际上有其他的名字的话就会中断。 我发现这个MSDN文章与众所周知的SID坚果我没有得到如何实际使用它们来解决我的问题。

如何find独立于Windows操作系统语言的本地组?

我不知道这是否有帮助。

 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,你可以找到其他值来进行实验。