The best way to resolve display username by SID?

Dennis C picture Dennis C · Dec 19, 2008 · Viewed 27.5k times · Source

I read a list of SIDs from the registry, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.

How would one resolve the display username (e.g. DOMAIN\user, BUILT-IN\user) given the SID string in C#?

Answer

Dennis C picture Dennis C · Dec 19, 2008

Just found it on the pinvoke.net.

Alternative Managed API: Available in .Net 2.0:

using System.Security.Principal;

// convert the user sid to a domain\name
string account = new SecurityIdentifier(stringSid).Translate(typeof(NTAccount)).ToString();