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

后端 未结 10 1056
囚心锁ツ
囚心锁ツ 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:06

    See here for a good answer:

    The best way to resolve display username by SID?

    The gist of it is this bit:

    string sid="S-1-5-21-789336058-507921405-854245398-9938";
    string account = new System.Security.Principal.SecurityIdentifier(sid).Translate(typeof(System.Security.Principal.NTAccount)).ToString();
    

    This approach works for me for non-local SID's over the active directory.

提交回复
热议问题