|
-
March 1st, 2003, 07:08 PM
#1
How to programatically find out (enumerate) all existing Windows User-Groups ??
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
-
March 2nd, 2003, 08:44 AM
#2
If you are talking about the AD groups (or domain groups):
Code:
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
-
March 2nd, 2003, 02:30 PM
#3
excellent martin, I should bookmark it.
Paresh
-
March 2nd, 2003, 02:45 PM
#4
I agree with pareshgh
-
April 6th, 2004, 01:36 PM
#5
Originally posted by MartinL
If you are talking about the AD groups (or domain groups):
Code:
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
--------------------------------------------
Tell me and I will forget
Show me and I will remember
Teach me and I will learn
-
April 6th, 2004, 01:49 PM
#6
You can also use WindowsPrincipals.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|