How can I convert from a SID to an account name in C#

后端 未结 10 1057
囚心锁ツ
囚心锁ツ 2020-12-01 02:56

I have a C# application that scans a directory and gathers some information. I would like to display the account name for each file. I can do this on the local system by g

10条回答
  •  猫巷女王i
    2020-12-01 03:06

    I am quite sure you will be able to use the accepted answer from here: Determine the LocalSystem account name using C#

    Basically, you can translate an instance of the SecurityIdentifier class to type NTAccount, from which you can get the user name. In code:

    using System.Security.Principal;
    
    SecurityIdentifier sid = new SecurityIdentifier("S-1-5-18");
    NTAccount acct = (NTAccount)sid.Translate(typeof(NTAccount));
    Console.WriteLine(acct.Value);
    

提交回复
热议问题