Ok I've figured out how to do the P/Invoke but I'm having a problem doing
the search. Below is the code, please let me know if there is something
that I am doing wrong. I'm banging my head against the wall just to do a
search on a stinking sid.
Code Below:
private void mdConvertSids()
{
foreach(string strTempStringSid in alSids)
{
string temp = strTempStringSid.Remove(0,1);
IntPtr ptrSID;
ConvertStringSidToSid(temp, out ptrSID);
byte[] btArray = new byte[28];
Marshal.Copy(ptrSID, btArray, 0, 28);
string strTempSID = "";
for (int i = 0; i < btArray.Length; i++)
{
strTempSID = strTempSID + btArray[i];
}
string strSID = "\\" + strTempSID;
System.String strBackSlash = "\\";
for(int intTemp = 0; intTemp < strSID.Length; intTemp++)
{
if(strSID.LastIndexOf(strBackSlash) + 3 > strSID.Length)
{
}
else
{
strSID = strSID.Insert(strSID.LastIndexOf(strBackSlash) + 3,"\\");
}
}
MessageBox.Show(strSID);
mdResolveSids(strSID);
Marshal.FreeHGlobal(ptrSID);
}
}
private void mdResolveSids(string strTempSid)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://Test-DC");
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectSID= " + strTempSid + ")");
foreach(System.DirectoryServices.SearchResult result in
mySearcher.FindAll())
{
MessageBox.Show( result.GetDirectoryEntry().Path );
}
}
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool ConvertStringSidToSid(string StringSid,out IntPtr
ptrSid);
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
Will,
Start by picking up the declaration from http://www.pinvoke.net
Then call it something like this
IntPtr pSid;
if ( ConvertStringSidToSid(stringSid, out pSid) ) {
// do stuff with SID
Marshal.FreeHGlobal(pSid);
}
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.