Does anybody know how to get the GUID for a windows user id?
cheers.
Printable View
Does anybody know how to get the GUID for a windows user id?
cheers.
In case anybody else needs it, here is a quick function i developed that will give the GUID plus a lot more.
Code:private void button3_Click(object sender, System.EventArgs e)
{
DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry(txtDirEntry.Text);
ds.Filter = "(samaccountname=" + txtAccountName.Text + ")";
SearchResultCollection src = ds.FindAll();
foreach (SearchResult sr in src)
{
ResultPropertyCollection myResultPropColl;
myResultPropColl = sr.Properties;
foreach(string strPropertyName in myResultPropColl.PropertyNames)
{
string strPropertyValue = "";
foreach( Object objProp in myResultPropColl[strPropertyName])
{
if ( objProp is ICollection )
{
ICollection usrSID =(ICollection) objProp;
foreach(object b in usrSID)
{
strPropertyValue = strPropertyValue + b.ToString();
}
}
else if ( objProp is Guid || objProp is Int32 || objProp is String )
{
strPropertyValue = objProp.ToString();
}
else
{
strPropertyValue = objProp.GetType().ToString();
}
}
listBox1.Items.Add(strPropertyName + ": " + strPropertyValue);
}
}
}
I don't have AD at home, so can't give exacts, but one can filter AD results in System.DirectoryServices (have excluded some lines of code above):
Code:string adFilter = "(&(sAMAccountName={0})(objectClass=person))";
adFilter = string.Format(adFilter, txtAccountName.Text);
ds.Filter = adFilter;
ds.PropertiesToLoad.Add("<Guid property name>");
// One can then call ds.FindOne() as only one result should be returned.