|
-
Aug 12th, 2005, 01:51 PM
#1
Thread Starter
Hyperactive Member
Get GUID for a User? [resolved]
Does anybody know how to get the GUID for a windows user id?
cheers.
Last edited by stingrae; Aug 12th, 2005 at 03:40 PM.
Reason: resolved
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Aug 12th, 2005, 03:39 PM
#2
Thread Starter
Hyperactive Member
Re: Get GUID for a User?
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);
}
}
}
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
-
Aug 12th, 2005, 05:25 PM
#3
Re: Get GUID for a User? [resolved]
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|