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

后端 未结 10 1052
囚心锁ツ
囚心锁ツ 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条回答
  •  臣服心动
    2020-12-01 03:24

    You can also get account name of special accounts like "Everyone" with code like this that will work regardless of user's language settings:

       SecurityIdentifier everyoneSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
       string everyone = everyoneSid.Translate(typeof(System.Security.Principal.NTAccount)).ToString();
    

提交回复
热议问题