Find user by SID

  • Thread starter Thread starter Will Bailey
  • Start date Start date
W

Will Bailey

I have a string version of a sid (ex...S-20-220) I need to be able to take
this sid and transfer it over to a name. My question is how do I do this.
I know that in order to search with
System.DirectoryServices.DirectorySearcher I need to have the binary version
of the SID. I've tried to use ConvertStringSidToSid but I think I'm
screwing up the syntax or something. I also saw there is a function out
there called LookupAccountSid. What should I be using to search with the
string SID. Any help would be greatly appreciated and some code examples
would be extremely helpful.

Thank you to every who replys in advance.

Will Bailey
 
Will,

The declaration should look like this:

[DllImport("Advapi32.dll", SetLastError=true)]
public static extern bool ConvertStringSidToSid(String StringSid, ref IntPtr
Sid);

Remember, you need to call LocalFree in order to release the sid. The
declaration for that is as follows:

[DllImport("Kernel32.dll", SetLastError=true)]
public static extern IntPtr LocalFree(IntPtr hMem);

Hope this helps.
 
Back
Top