Created
December 15, 2017 05:37
-
-
Save ShekharReddy4/2bf7a3784fe6014b854270d5dc9ccf37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.DirectoryServices; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName); | |
DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group"); | |
List<string> adminUsers = new List<string>(); | |
object members = admGroup.Invoke("members", null); | |
foreach (object groupMember in (IEnumerable)members) | |
{ | |
DirectoryEntry member = new DirectoryEntry(groupMember); | |
adminUsers.Add(member.Name); | |
Console.WriteLine(member.Username); | |
} | |
adminUsers.Sort(); | |
foreach (var user in adminUsers) | |
{ | |
Console.WriteLine(user); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment