Enumerate NT Group membership on remote computer
-
I need to enumerate members of Administrators group on all computers remotely. I should be able to specify computername, username & password. Has WMI got any class to enumerate group membership ? Also, has WinNT provider got capability to connect to remote machines with alternate credentials? Any code will be of great help. Thanks in anticiaptions. h.
before c# there was darkness
-
I need to enumerate members of Administrators group on all computers remotely. I should be able to specify computername, username & password. Has WMI got any class to enumerate group membership ? Also, has WinNT provider got capability to connect to remote machines with alternate credentials? Any code will be of great help. Thanks in anticiaptions. h.
before c# there was darkness
Hello. I've actually recently written a program to manage user groups on remote servers, including add an expiration date/time when that user will be removed. I'll be posting an article on it soon. Here is some code that should help you out. You will need to add a reference to System.DirectoryServices, and using statements for System.DirectoryServices and System.Collections:
String entryString = "WinNT://" + computerName + ",computer"; DirectoryEntry dirEntry = new DirectoryEntry(entryString, username, password); foreach (DirectoryEntry entry in dirEntry.Children) { if (entry.SchemaClassName.Equals("group", StringComparison.CurrentCultureIgnoreCase)) { if (entry.Name.Equals("Administrators")) { object members = entry.Invoke("Members", null); foreach (object member in (IEnumerable)members) { DirectoryEntry memberEntry = new DirectoryEntry(member); String name = memberEntry.Name; String path = memberEntry.Path; MessageBox.Show(path + "\n" + name + "\n" + memberEntry.SchemaClassName); } } } }
-
Hello. I've actually recently written a program to manage user groups on remote servers, including add an expiration date/time when that user will be removed. I'll be posting an article on it soon. Here is some code that should help you out. You will need to add a reference to System.DirectoryServices, and using statements for System.DirectoryServices and System.Collections:
String entryString = "WinNT://" + computerName + ",computer"; DirectoryEntry dirEntry = new DirectoryEntry(entryString, username, password); foreach (DirectoryEntry entry in dirEntry.Children) { if (entry.SchemaClassName.Equals("group", StringComparison.CurrentCultureIgnoreCase)) { if (entry.Name.Equals("Administrators")) { object members = entry.Invoke("Members", null); foreach (object member in (IEnumerable)members) { DirectoryEntry memberEntry = new DirectoryEntry(member); String name = memberEntry.Name; String path = memberEntry.Path; MessageBox.Show(path + "\n" + name + "\n" + memberEntry.SchemaClassName); } } } }
Hello there, The problem is that I need to connect with alternate credentials. All my servers have different password. WinNT provider by default uses pass-through authentication, which means takes your currently logged on priviledges to connect to remote computer. This works good if I have common password as I login using same passowrd. But that is very risky, a malicious code can then play aroumd. I am also trying to find out way to connect using alternate credentials, If you get to know first please post it :) By the way, there's option in directory entry class to specify user/password but in that case the output is blank, not sure why. Good day. h.
before c# there was darkness