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

thanks.
santosh.

Recommended Answers

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 …
Jump to Post

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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.