views:

61

answers:

1

I'm using this snippet of code to output a list of all the computers on my network (the language is jscript.net, but it's just a small manipulation of C#).

    var parentEntry = new DirectoryEntry();

    parentEntry.Path = "WinNT:";
    for(var childEntry in parentEntry.Children) {
        if(childEntry.SchemaClassName == "Domain") {
            var parentDomain = new TreeNode(childEntry.Name); 
            this.treeView1.Nodes.Add(parentDomain);

            var subChildEntry : DirectoryEntry;
            var subParentEntry = new DirectoryEntry();
            subParentEntry.Path = "WinNT://" + childEntry.Name;
            for(subChildEntry in subParentEntry.Children) {
                var newNode1 = new TreeNode(subChildEntry.Name);
                if(subChildEntry.SchemaClassName == "Computer") {
                    parentDomain.Nodes.Add(newNode1);
                }
            }
        }

    }

I have 2 issues with this:

1) It is extremely slow. There's about 100 computers showing, and it takes about 1 minute to load.

2) I want to get only a list of computers that are currently online.

This can be done because I've seen other programs doing it and they are much faster, also they're able to show only the ones online.

Am I missing something?

A: 

I would look at Linq To Active Directory found on CodePlex

You'd also have to define "my network". Your subnet? Your Organizational Unit? Your domain? Your forest?

Also consider where your LDAP server is that you are querying. Is it close or is it on the other end of a remote link?

Also what do you consider "online"? Do you expect to be able to ping it? Do you expect to be able to connect to it and perform an operation?

There are many things to consider here. Also if you have other infrastructure components such as an SCCM / SMS server they can often be queried much faster since all of the discovery data has flowed up into the data warehouse.

Christopher Painter
For "network" I mean my domain.
Luca Matteis