To list the Domains and their respective Groups, Schemas, User and Computer use DirectoryEntry and enumerate through the Children of the respective Entry. Check out the following code for more understanding
Include Reference to System.DirectoryServices in the project
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry dirEntry = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry de in dirEntry.Children)
{
if (de.SchemaClassName == "Domain")
{
Console.WriteLine("Domain : " + de.Name);
Console.WriteLine("=================\n");
foreach (DirectoryEntry de2 in de.Children)
{
Console.WriteLine(" Name : " + de2.Name + " \t\t Type : " + de2.SchemaClassName);
}
}
de.Dispose();
}
dirEntry.Dispose();
Console.ReadLine();
}
}
}
Image may be NSFW.
Clik here to view.

Clik here to view.
