1

当我登录到远程桌面时,我切换了某个域 - 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);
                }
            }
        }
    }
4

0 回答 0