Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every body

i want to find list of all domains in windows xp using c#
becuase of providing security under domain environment of the login users into my c# application

i tried on this code i will find only admin users.

but i want to maintain all domains and users in windows xp pc using c# any one give good sugisstions on this with best examples.

here is my code

C#
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
            // DirectoryEntry admGroup = localMachine.Children.Find("Guests", "group");
           // DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group");
            DirectoryEntry admGroup = localMachine.Children.Find("users", "group");
            //DirectoryEntry admGroup = localMachine.Children.Find("TestUser1", "group");
            object members = admGroup.Invoke("members", null);
            foreach (object groupMember in (IEnumerable)members)
            {
                DirectoryEntry member = new DirectoryEntry(groupMember);
                listBox1.Items.Add(member.Name);
            }
Posted
Updated 2-Dec-11 23:38pm
v2
Comments
uspatel 3-Dec-11 5:38am    
Pre tag added

1 solution

Add a reference to System.DirectoryServices.dll

C#
using (var forest = Forest.GetCurrentForest())
{
    foreach (Domain domain in forest.Domains)
    {
        Debug.WriteLine(domain.Name);
        domain.Dispose();
    }
}




Extracted from here :
http://stackoverflow.com/questions/2596419/how-to-get-a-list-of-all-domains[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900