Hi,
Can anyone let me know how to list all the users from a windows active directory using C#.

thanks.
santosh.

Recommended Answers

All 2 Replies

UP


How to list users , IPs on Windows server using C#


Thanks

Hi,
Can anyone let me know how to list all the users from a windows active directory using C#.

thanks.
santosh.

Hi,
First include System.DirectoryServices.dll.

Then try this code

DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
string userNames="Users :  ";
foreach (DirectoryEntry child in directoryEntry.Children)
{
    if (child.SchemaClassName == "User")
    {
        userNames += child.Name + Environment.NewLine   ;         
    }
    
}
MessageBox.Show(userNames);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.