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

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.

How to get the logon SID in C#

I’m afraid you have to resort to using P/Invoke. There’s an example how to do it at pinvoke.net (please see the bottom of the page): Result = GetTokenInformation(WindowsIdentity.GetCurrent().Token, TOKEN_INFORMATION_CLASS.TokenSessionId , TokenInformation , TokenInfLength , out TokenInfLength ); Please note that I changed the example by altering just one line, I replaced TOKEN_INFORMATION_CLASS.TokenUser with TOKEN_INFORMATION_CLASS.TokenSessionId which … Read more