Results 1 to 3 of 3

Thread: Get GUID for a User? [resolved]

  1. #1

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401

    Resolved 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

  2. #2

    Thread Starter
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401

    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

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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
  •  



Click Here to Expand Forum to Full Width