在Active Directory中找不到域

时间:2012-11-19 14:22:30

标签: .net active-directory

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

0 个答案:

没有答案