How to list domains running code from a non-domain computer?

柔情痞子 提交于 2019-12-11 06:41:42

问题


In my application I need to get Active Directory forest and list the domains hierarchy.

I was given the Active Directory account that has necessary permissions. However my development computer is NOT on the domain and can not be added to the domain.

Here is the code that I am using to get the forest and access the root domain:

 // I also tried to add a Global Catalog port: 192.168.2.11:3268, no success
 DirectoryContext dc = new DirectoryContext(
      DirectoryContextType.Forest, "192.168.2.11", “Login1”, “pass1”);
 Forest f = Forest.GetForest(dc);
 Console.WriteLine("Forest name: " + f.Name);
 Console.WriteLine("Root domain: " + f.RootDomain);

How do I modify it to discover domains in case I run it on a computer that is not on a domain?


回答1:


Even the computer is not joined to domain, you can still set its DNS server to one that can resolve the names in AD.

Ideally you can use the same DNS server that is used by the DC.

After the above change, you should be able to create the Forest object with the forest name. Then, to get the domains, simply call the Domains property of Forest.



来源:https://stackoverflow.com/questions/27908447/how-to-list-domains-running-code-from-a-non-domain-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!