Home
Manage Your Code
Snippet: Get all users in a local Windows Group (C#)
Title: Get all users in a local Windows Group Language: C#
Description: Gets all the members (could be users and groups) that belong to a particular local Windows group. IE Get all the members of the POWER USERS group. Views: 104
Author: Garth Sweet Date Added: 4/15/2008
Copy Code  
1        private void ListMembersInGroup(string ComputerName, string GroupName)
2        {
3            // Based on examples from http://bytes.com/forum/thread259945.html
4      	
5            // Connect to a local server using the WinNT provider interface
6            using (DirectoryEntry groupEntry = new DirectoryEntry(string.Format("WinNT://{0}/{1},group", ComputerName, GroupName)))
7            {
8                object members = groupEntry.Invoke("Members");
9                foreach (object member in (IEnumerable)members)
10                {
11                    DirectoryEntry de = new DirectoryEntry(member);
12                    Console.WriteLine("ADsPath " + de.Path + " Name: " + de.Name);
13                }
14            }
15        }
Usage
using System.DirectoryServices;
Notes
Email bitmugger@gmail.com with comments/questions.