当我登录远程桌面时,我会切换某个域 - USPHC,然后输入登录名和密码。我需要在代码中找到这个域名。我编写了WinForm应用程序来测试它。但是我无法在DirectorySearcher类的帮助下找到域:
DirectoryEntry dir = new DirectoryEntry();
var search = new DirectorySearcher(dir);
search.Filter = "(&(distinguishedName=USPHC))";
或在DirectoryEntry类的帮助下:
DirectoryEntry de = new DirectoryEntry();
foreach (DirectoryEntry child in de.Children)
{
listBoxDomains.Items.Add(child);
}
private void listBoxDomains_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (listBoxDomains.SelectedIndex != -1)
{
DirectoryEntry currentDomain = (listBoxDomains.SelectedItem as DirectoryEntry);
if (currentDomain.Children != null)
{
listBoxDomains.Items.Clear();
foreach (DirectoryEntry de in currentDomain.Children)
{
listBoxDomains.Items.Add(de);
}
}
}
}