954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get Users from Windows Active Directory

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

thanks.
santosh.

santoo
Newbie Poster
17 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

UP


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


Thanks

Eng_Gaza
Newbie Poster
4 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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);
selvaganapathy
Posting Pro
547 posts since Feb 2008
Reputation Points: 44
Solved Threads: 100
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You