views:

14

answers:

0

Hello, 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?