Whoami

| | No TrackBacks

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);
    }
  }
}

No TrackBacks

TrackBack URL: http://www.iwebthereforeiam.com/cgi-bin/mt/mt-tb.cgi/55

Leave a comment

Verification (needed to reduce spam):

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.32-en

About this Entry

This page contains a single entry by Hugh Brown published on September 18, 2007 3:48 AM.

Cheat sheets for python was the previous entry in this blog.

Online language translation is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.