Solved

Listing Windows UserGroups,etc.

Posted on 2003-11-19
4
224 Views
Last Modified: 2010-04-16
I'm looking for some simple code that allows us to list the Windows user groups against a server.
Ideally this would include things like Administrators, etc.
How can this be done against a given domain ?
Any help would be appreciated.
I'm just starting looking at this and looking for a head start ....
Thanks in advance
Steve
0
Comment
Question by:StevenK
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Divinity
ID: 9787865
You could take a look at the System.Management namespace and use it to do WQL queries.
0
 

Author Comment

by:StevenK
ID: 9788013
How do I make use of this ?
I'm in uncharted waters .... :(
Steve
0
 
LVL 2

Accepted Solution

by:
jrberg earned 25 total points
ID: 10121978
Add a reference in your project to System.DirectoryServices and do the following.

using System.DirectoryServices;

static void Main()
{
        // In the LDAP string the DC='s represent Hostname Segments (ex. my.domain.com) replace with yours
        // Replace Domaincontroller with your domaincontrollers name
        string Enterprise = "LDAP://domaincontroller/CN=Users,DC=my,DC=domain,DC=com";
        DirectoryEntry myDirectoryEntry = new DirectoryEntry( Enterprise );
        foreach( DirectoryEntry de in myDirectoryEntry.Children )
        {
           Console.WriteLine( de.Name );
        }
}

Hope this is what your looking for,
Jerry

0
 
LVL 2

Expert Comment

by:jrberg
ID: 10122063
One more thing now that I read the question again

1) If you want all the users on the domain use this LDAP in my last code post
 "LDAP://domaincontroller/CN=Users,DC=my,DC=domain,DC=com";

2) If you want all the groups on the domain use this LDAP in my last code post
 "LDAP://domaincontroller/DC=my,DC=domain,DC=com";

This should give you what you want,
Jerry
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now