Find user by SID

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top