Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Listing Windows UserGroups,etc.

Posted on 2003-11-19
4
228 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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