C# Error reading domains in different domain

143 views Asked by At

I have this code that works just fine when logged onto a domain:

DirectoryContext context = new DirectoryContext(DirectoryContextType.DirectoryServer, serverIP, username, password);            

var forest1 = Forest.GetForest(context);

using (var forest = Forest.GetForest(context))
{
    foreach (Domain domain in forest.Domains)
    {
        DirectoryEntry deDomain = domain.GetDirectoryEntry();
        MessageBox.Show(String.Format("{0} {1} {2}", domain.Name, deDomain.Path, deDomain.Guid));
    }
}

And it also works fine when accessing a domain that I am not logged onto ie. the connection goes through ok and forest.Domains is populated.

The problem I have is that whenever I try to access any property of the domain object (eg. domain.DomainMode) I get 'Unknown error (0x80005000)' - any ideas?

0

There are 0 answers