Farna
Farna

Reputation: 1176

retrieve username and nickname from active directory on local network

I want to read the username and NickName of any users on my local network from server's active directory. How can I do it? Thanks alot.

Upvotes: 0

Views: 374

Answers (1)

Porco
Porco

Reputation: 4203

public void getUser()
{
 DirectoryServices.SearchResult myResult;
 string filterString = string.Empty;
 string EntryString = "LDAP:// <Your AD Domain here>";
 DirectoryServices.DirectorySearcher myDirectorySearcher = new DirectoryServices.DirectorySearcher(new DirectoryServices.DirectoryEntry(EntryString, "Username", "Password"));
 string tempStr;
 string[] splStr = new string[3];

 filterString = "(sAMAccountName=" + Username + ")";
 myDirectorySearcher.Filter = filterString;
 myDirectorySearcher.PropertiesToLoad.Add("cn");
 myResult = myDirectorySearcher.FindOne();
 splStr = Regex.Split(myResult.Properties("cn").Item(0).ToString, " ");
 tempStr = splStr(1).ToString + " " + splStr(0).ToString;
 Label1.Text = "Hello " + tempStr;
}

Upvotes: 1

Related Questions