目录服务,搜索所有可用的提供商

发布于 2024-09-09 01:51:29 字数 1557 浏览 9 评论 0原文

我有以下方法用于在本地计算机(首先完成)或当前林中搜索用户组。

public string FindUserGroup(string group)
    {
        //Search local computer
        using (DirectorySearcher searcher = new DirectorySearcher(new DirectoryEntry()))
        {
            searcher.Filter = "(&(objectClass=group)(|(cn=" + group + ")(dn=" + group + ")))";
            SearchResult result = searcher.FindOne();
            if (result != null)
                return TranslateDirectoryEntryPath(result.GetDirectoryEntry().Path);
        }

        //Search current forest
        Forest forest = Forest.GetCurrentForest();
        foreach (Domain domain1 in forest.Domains)
        {
            using (DirectorySearcher searcher = new DirectorySearcher(domain1.GetDirectoryEntry()))
            {
                searcher.Filter = "(&(objectClass=group)(|(cn=" + group + ")(dn=" + group + ")))";
                SearchResult result = searcher.FindOne();
                if (result != null)
                    return TranslateDirectoryEntryPath(result.GetDirectoryEntry().Path);
            }
        }

        return string.Empty;
    }

我的问题是,我们作为示例说“domain.local”和“mydomain.local”,而我当前的登录名绑定到“domain.local”,那么使用下面的命令将无法在“mydomain.local”中找到任何内容。本地”,即使我通过 Windows 用户界面也能够。

当我不一定了解所有可查看的提供商时,如何从计算机的角度搜索所有可查看的提供商?我真的必须自己做登记工作吗?


编辑:

这两个域的一个区别是当我在对象浏览器对话框中选择“位置”时它们所处的“级别”,它的布局为:

  • 计算机
  • 整个方向
    • 域.本地
  • mydomain.local

所以“mydomain.local”存在于所谓的“整个目录”之外,但我的计算机可以找到它,这有什么区别吗?

I have the following method used for searching for a User Group either on the local computer (done first) or in the Current Forest.

public string FindUserGroup(string group)
    {
        //Search local computer
        using (DirectorySearcher searcher = new DirectorySearcher(new DirectoryEntry()))
        {
            searcher.Filter = "(&(objectClass=group)(|(cn=" + group + ")(dn=" + group + ")))";
            SearchResult result = searcher.FindOne();
            if (result != null)
                return TranslateDirectoryEntryPath(result.GetDirectoryEntry().Path);
        }

        //Search current forest
        Forest forest = Forest.GetCurrentForest();
        foreach (Domain domain1 in forest.Domains)
        {
            using (DirectorySearcher searcher = new DirectorySearcher(domain1.GetDirectoryEntry()))
            {
                searcher.Filter = "(&(objectClass=group)(|(cn=" + group + ")(dn=" + group + ")))";
                SearchResult result = searcher.FindOne();
                if (result != null)
                    return TranslateDirectoryEntryPath(result.GetDirectoryEntry().Path);
            }
        }

        return string.Empty;
    }

My problem is that we as an example have say "domain.local" and "mydomain.local", and my current login is bound to "domain.local", then using below won't be able to find anything in "mydomain.local", even if I through the Windows User Interface is able to.

How can I search all viewable providers from my computers perspective when I don't nessesarily know them all? Do I REALLY have to do the Registry Work my self?


Edit:

One difference in the 2 domains is the "level" they are on when I in an object browser dialog chooses "Locations", it layouts as:

  • Computer
  • Entire Direction
    • domain.local
  • mydomain.local

So "mydomain.local" excists outside what is referred to as "Entire Directory", yet my computer can locate it, if that makes any difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖公主 2024-09-16 01:51:29

我没有看到问题,因为这里的代码已经绑定到其他域。

foreach (Domain domain1 in forest.Domains)
{
    using (DirectorySearcher searcher = new DirectorySearcher(domain1.GetDirectoryEntry()))
    {

您是否想说稍后您自己绑定 DirectoryEntry,并且无法找到来自其他域的对象?

I don't see a problem as this code here would have already be binded to the other domains.

foreach (Domain domain1 in forest.Domains)
{
    using (DirectorySearcher searcher = new DirectorySearcher(domain1.GetDirectoryEntry()))
    {

Are you trying to say that later on you're binding a DirectoryEntry on your own, and you can't find objects from other domain?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文