I am trying to get a list of all the active computers running on my
domain.
I'm writing some remote management style software with WMI, which
works fine when i know the computer name, but i just want to be able
to produce a list and work it from there.
I found the following method:
String path = "WinNT://MY.DOMAIN.COM";
String username = "administrator";
String password = "password";
DirectoryEntry domain = new DirectoryEntry(path, username, password);
DirectoryEntries computers = domain.Children;
computers.SchemaFilter.Add("computer");
foreach(DirectoryEntry Computer in computers)
{
String a = Computer.Name;
}
which i found on this group somewhere, but i keep getting the
following error:
Multiple connections to a server or shared resource by the same user,
using more than one user name, are not allowed.
This happens whether i use administrator or my own username (or even
if i am logged in as administrator).
-
I was able to use a similar method:
DirectoryEntry objDE = new DirectoryEntry("LDAP://my.domain.com");
DirectorySearcher objSearcher = new DirectorySearcher(objDE);
objSearcher.Filter = ("(ObjectClass=computer)");
Which works.. but this returns computers that haven't been switched on
in a long long time.
In fact it generates almost 3 times as many results as a NET VIEW
command.
I could ping each name and see if it responds, but this will add a lot
onto the execution time, which i'm trying to avoid.
(Plus it has CN= at the beginning of every name, which is a little
annoying.)
So, can anyone inform me how to solve the first problem? Or how to
filter for only active/switched on computers in the second method?
Or would i be best going down another route?
I was thinking of just running a NET VIEW and catching the output,
filtering it and voila! But that seems like a really obfuscated way of
going about it.
Cheers