Click to See Complete Forum and Search --> : How to programatically find out (enumerate) all existing Windows User-Groups ??
Honza
March 1st, 2003, 06:08 PM
Hi to all
What I need is to enumerate all existing windows user-groups (those like Administrators, Power-Users etc. but even my own created groups, I think you know what I mean) - all within some C# code.
I thought this might be easy but I searched all the Internet to find the solution, however, I still can't do it...
Is there anybody who could help me ???
Thanks a lot, I really really need your help.
Honza
MartinL
March 2nd, 2003, 07:44 AM
If you are talking about the AD groups (or domain groups):
using System;
using System.DirectoryServices;
class Class1
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://YourDomainName");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=group)";
foreach (SearchResult res in searcher.FindAll())
{
Console.WriteLin(res.GetDirectoryEntry().Name.ToString());
}
}
}
Martin
pareshgh
March 2nd, 2003, 01:30 PM
excellent martin, I should bookmark it.
Paresh
underwar
March 2nd, 2003, 01:45 PM
I agree with pareshgh :cool:
womalley
April 6th, 2004, 01:36 PM
Originally posted by MartinL
If you are talking about the AD groups (or domain groups):
using System;
using System.DirectoryServices;
class Class1
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://YourDomainName");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=group)";
foreach (SearchResult res in searcher.FindAll())
{
Console.WriteLin(res.GetDirectoryEntry().Name.ToString());
}
}
}
Martin
Very cool ..
I do have a question that kind of goes with this.
Is there a way to findout what users belong to each group?
So I could generate a listing
GROUP:
GroupName
USERS IN GROUP:
User1
User2
...... ect
Thanks
Will
TheCPUWizard
April 6th, 2004, 01:49 PM
You can also use WindowsPrincipals.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.