How to get a list of all domains?

后端 未结 2 1778
清酒与你
清酒与你 2021-01-01 03:32

I\'m trying to get all domains that are available in the Windows Login dialog (in the Domain dropdown).

I\'ve tried the following code but it only returns the domai

相关标签:
2条回答
  • Take a look at this CodeProject article. You'll find a simple code snippet to enumerate domains in the current forest.

    0 讨论(0)
  • 2021-01-01 04:06

    Add a reference to System.DirectoryServices.dll

    using (var forest = Forest.GetCurrentForest())
    {
        foreach (Domain domain in forest.Domains)
        {
            Debug.WriteLine(domain.Name);
            domain.Dispose();
        }
    }
    
    0 讨论(0)
提交回复
热议问题