【问题标题】:How do I locate a local group in locale-independent way?如何以独立于区域设置的方式定位本地组?
【发布时间】:2012-08-06 08:48:46
【问题描述】:

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

我的代码在搜索时传递了一个硬编码的字符串:

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

因此,如果该组实际上有其他名称,它将中断。我发现 this MSDN article with well-known SIDs nut 我不知道如何实际使用它们来解决我的问题。

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

【问题讨论】:

    标签: c# .net windows localization internationalization


    【解决方案1】:

    我不知道这是否有帮助。

    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"
    

    我从 this page 获取了 SID,您可以在其中找到其他值进行实验。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多