안녕하세요 저는 사용자가 텍스트 상자에 어떤 컴퓨터를 검색 할 것인지를 입력 할 수있는 기능을 내 Windows 프로그램에 추가하려고했습니다. Active Directory. 사용자는 텍스트 상자에 검색 문자열을 입력 한 다음 단추를 누르면 해당 검색 결과와 일치하는 컴퓨터가 별도의 검색 상자에 나타납니다. 지금까지 제 코드가 있습니다.Active Directory에서 사용자 입력을 사용하여 컴퓨터 이름을 검색하십시오.
computername1
computername2
computername3
감사 :
은 또한 각각의 컴퓨터 이름과 같은 별도의 행에 싶습니다!
이 버튼의 모양 안에 무엇을 : 당신이 .NET 3.5 및 최대에있는 경우
List<string> hosts = new List<string>();
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://servername";
try
{
string adser = txtAd.Text; //textbox user inputs computer to search for
DirectorySearcher ser = new DirectorySearcher(de);
ser.Filter = "(&(ObjectCategory=computer)(cn=" + adser + "))";
ser.PropertiesToLoad.Add("name");
SearchResultCollection results = ser.FindAll();
foreach (SearchResult res in results)
//"CN=SGSVG007DC"
{
string computername = res.GetDirectoryEntry().Properties["Name"].Value.ToString();
hosts.Add(computername);
//string[] temp = res.Path.Split(','); //temp[0] would contain the computer name ex: cn=computerName,..
//string adcomp = (temp[0].Substring(10));
//txtcomputers.Text = adcomp.ToString();
}
txtcomputers.Text = hosts.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
de.Dispose();//Clean up resources
}
[이전 질문에 대한 답변을 수락해야합니다] (http://meta.stackexchange.com/q/5234/153998). 이것은 당신을 돕기 위해 자신의 시간을 보냈던 사람들에 대한 감사를 나타내며, 미래의 질문에 답할 수있는 기회를 향상시킵니다. –