0
我想从服务器的活动目录中读取本地网络上任何用户的用户名和NickName。我该怎么做?非常感谢。从本地网络上的活动目录中检索用户名和昵称
我想从服务器的活动目录中读取本地网络上任何用户的用户名和NickName。我该怎么做?非常感谢。从本地网络上的活动目录中检索用户名和昵称
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;
}
@rmcdonald:用这个代码我可以看到用户名和昵称? – Farna 2011-04-01 18:37:56
对不起,要添加其他字段只需使用myDirectorySearcher.PropertiesToLoad.Add()。例如,要获得givenname(我认为是昵称): myDirectorySearcher.PropertiesToLoad.Add(“givenname”) – Porco 2011-04-01 18:50:23
@rmcdonald:我是新程序员,对不起,您的意思是我可以将2个属性添加到myDirectorySearcher ?? myDirectorySearcher。 PropertiesToLoad.Add( “CN”); 和myDirectorySearcher.PropertiesToLoad.Add(“givenname”)好吗? – Farna 2011-04-01 18:56:54