获取帐户名称的其他别名

时间:2015-02-13 17:34:52

标签: windows system alias account sid

Windows中的SYSTEM帐户的SID为S-1-5-18。它的别名为NT AUTHORITY\SYSTEM。我可以使用以下方法在Windows终端中查询系统帐户名称:

C:\Windows\system32>wmic sysaccount get name

此查询将返回SYSTEM作为系统帐户的一部分,但如何为此帐户获取其他别名,例如NT AUTHORITY\SYSTEM?在Windows中有标准的方法吗?

我只是使用SysInternals的psgetsid工具成功完成了这项工作:

C:\Users\User\Downloads\PSTools>psgetsid SYSTEM

PsGetSid v1.44 - Translates SIDs to names and vice versa
Copyright (C) 1999-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

SID for NT AUTHORITY\SYSTEM:
S-1-5-18

1 个答案:

答案 0 :(得分:1)

Greg Zakharov shed some light on this for me and he should take full credit for this answer

using System;
using System.Security.Principal;

namespace SIDTranslation
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                try
                {
                    NTAccount account = new NTAccount(Console.ReadLine());
                    IdentityReference identity = account.Translate(typeof(SecurityIdentifier));
                    Console.WriteLine("SID for {0}" + Environment.NewLine + "{1}", identity.Translate(typeof(NTAccount)), identity);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
    }
}

例如,在SYSTEM中运行和输入会产生以下输出:

SID for NT AUTHORITY\SYSTEM
S-1-5-18

帐户名称基本上从其部分NTAccount格式转换为其SID,然后再返回以生成完整的NTAccount名称。我不完全确定为什么会这样,但确实如此。

相关问题