using System; using System.DirectoryServices; using System.Runtime.InteropServices; using System.Reflection; using activedsnet; class Test { static string domainPath = "WinNT://myDomainName/"; // WinNT provider - domain name private static void ListMembersInGroup(string GroupName) { IADsMembers MembersCollection = null; try { // someValidUser and hisPwd are user credentials to bind to the DC DirectoryEntry groupEntry = new DirectoryEntry( domainPath + GroupName ,"someValidUser", "hisPwd", AuthenticationTypes.Secure); PropertyCollection pcoll = groupEntry.Properties; // invoke native method "members" MembersCollection = groupEntry.Invoke("Members") as IADsMembers; object[] filter = {"user"}; MembersCollection.Filter = filter; // enumerate members of collection object that supports the IADsMembers interface // ADSI provider doesn't support count property try { foreach (IADsUser member in MembersCollection) { Console.WriteLine("===================================================="); Console.WriteLine("ADsPath "+ member.ADsPath + " Name: " + member.Name ); ListUserProp(member.Name); } } catch (COMException e) { Console.WriteLine("Error: {0}",e.Message); } } catch (COMException e) { Console.WriteLine(e.Message); } } / Show user props private static void ListUserProp(string UserName) { DirectoryEntry userEntry = null; try { userEntry = new DirectoryEntry(domainPath + UserName,"Administrator", "kevin", AuthenticationTypes.Secure); PropertyCollection pcoll = userEntry.Properties; Console.WriteLine(pcoll.Count); foreach(string sc in pcoll.PropertyNames) Console.WriteLine(sc + "\t" + pcoll[sc].Value); } catch (COMException e) { Console.WriteLine(e.Message); } finally { userEntry.Close(); } } public static void Main() { // List all members in group "Domain Users" ListMembersInGroup("Domain Users"); } }>How can you return a list of users that belong to a domain?