Code to translate user name to Windows SID
using System;
using System.DirectoryServices;
using System.Security.Principal;
class Program
{
static void Main(string[] args)
{
foreach (string arg in args)
{
string path = String.Format("WinNT://KBCFP/{0}", arg);
DirectoryEntry root =
new DirectoryEntry(path, null, null,
AuthenticationTypes.Secure);
SecurityIdentifier si =
new SecurityIdentifier((byte[])
root.Properties["objectSid"][0], 0);
Console.WriteLine("{0}: {1}", arg, si.Value);
}
}
}

Leave a comment