473,761 Members | 10,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List Computers on my domain

JB
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);
DirectoryEntrie s computers = domain.Children ;
computers.Schem aFilter.Add("co mputer");
foreach(Directo ryEntry 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") ;
DirectorySearch er objSearcher = new DirectorySearch er(objDE);
objSearcher.Fil ter = ("(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

May 22 '07 #1
4 7696
On 2007-05-22 17:42:57 +0100, JB <ja*******@gmai l.comsaid:
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);
DirectoryEntrie s computers = domain.Children ;
computers.Schem aFilter.Add("co mputer");
foreach(Directo ryEntry 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") ;
DirectorySearch er objSearcher = new DirectorySearch er(objDE);
objSearcher.Fil ter = ("(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
The way I tackled a similar problem was to first omit any computer
objects that are disabled then calculate the likelyhood of a computer
object being "active" based on the PwdLastSet attribute. This will
narrow your search somewhat but you'll stil run into computers that are
not switched on at that moment in time. Actually, I am planning on
implementing a similar feature such that the results of the
DirectorySearch er can be fed into another interactive process and my
plan is to use a WMI ping to determine if the computer can be accessed
remotely.

narrowing the search to include only non-disabled objects:

* searcher.filter =
"(&(ObjectCateg ory=computer)(! UserAccountCont rol:1.2.840.113 556.1.4.803:=2) )";
speed

up the search by only selecting the attributes you are interested in:

* searcher.proper tiesToLoad.Add( "cn");
* searcher.proper tiesToLoad.Add( "PwdLastSet ");

I should say at this point I have to calculate the PwdLastSet time
because we are not running a windows 2003 domain in native mode. I
believe in 2k3 the LastLogon time stamp (or something similar) is
replicated to all DCs which will make this method redundant. If you
have a 2k3 domain I would investigate looking for that attribute.
However . . .

.. . .Now calculate a suitable cut off period based on the PwdLastSet attribute
[your routine for itterating through the list of comp objects in the
searchresults]

* DateTime today = DateTime.Now;
* DateTime cutoff = today.Subtract( new TimeSpan(30,0,0 ,0)); //30 Days
* //I'm not sure if the following line is exactly necessary but I use
it as I need to output a friendly time
* DateTime compPwdLastSet =
DateTime.FromFi leTime((long)co mp.Properties["PwdLastSet "][0]);

* If (compPwdLastSet <= cutoff)
* {
* //object is probably stale
* }
I'd be interested to see what you do with the machines once you have a list :-)

Cheers,
n

May 23 '07 #2
JB
>
The way I tackled a similar problem was to first omit any computer
objects that are disabled then calculate the likelyhood of a computer
object being "active" based on the PwdLastSet attribute. This will
narrow your search somewhat but you'll stil run into computers that are
not switched on at that moment in time. Actually, I am planning on
implementing a similar feature such that the results of the
DirectorySearch er can be fed into another interactive process and my
plan is to use a WMI ping to determine if the computer can be accessed
remotely.

narrowing the search to include only non-disabled objects:

* searcher.filter =
"(&(ObjectCateg ory=computer)(! UserAccountCont rol:1.2.840.113 556.1.4.803:=2) )";

speed

up the search by only selecting the attributes you are interested in:

* searcher.proper tiesToLoad.Add( "cn");
* searcher.proper tiesToLoad.Add( "PwdLastSet ");

I should say at this point I have to calculate the PwdLastSet time
because we are not running a windows 2003 domain in native mode. I
believe in 2k3 the LastLogon time stamp (or something similar) is
replicated to all DCs which will make this method redundant. If you
have a 2k3 domain I would investigate looking for that attribute.
However . . .

. . .Now calculate a suitable cut off period based on the PwdLastSet attribute

[your routine for itterating through the list of comp objects in the
searchresults]

* DateTime today = DateTime.Now;
* DateTime cutoff = today.Subtract( new TimeSpan(30,0,0 ,0)); //30 Days
* //I'm not sure if the following line is exactly necessary but I use
it as I need to output a friendly time
* DateTime compPwdLastSet =
DateTime.FromFi leTime((long)co mp.Properties["PwdLastSet "][0]);

* If (compPwdLastSet <= cutoff)
* {
* //object is probably stale
* }

I'd be interested to see what you do with the machines once you have a list :-)

Cheers,
n

Thanks, that has helped me, but now I have another, very strange
error..
The results it returns are still pretty far wide of the mark.
I used the "LastLogon" Property and filtered out any machines over 30
days ago.
Now its still showing machines that havent been used in months/years.
And some anomalies are cropping up.

It shows the following computer names for example:
10-07
10-07-Vista

Neither of these are now valid machines, however,
When i ping these from a command prompt, they show the same IP
address.
when i ping that IP address with the -a switch to resolve the machine
name, It returns a third, completely different name.
Some PC's are ok, others are not.

This is a network/active directory problem i'm sure. But if anyone
knows why it would do this I would appreciate it.

No simple way to simply reproduce the list from Net View or My Network
Places? Those show the exact results i'm looking for..
May 23 '07 #3
"JB" <ja*******@gmai l.comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .

The way I tackled a similar problem was to first omit any computer
objects that are disabled then calculate the likelyhood of a computer
object being "active" based on the PwdLastSet attribute. This will
narrow your search somewhat but you'll stil run into computers that are
not switched on at that moment in time. Actually, I am planning on
implementing a similar feature such that the results of the
DirectorySearc her can be fed into another interactive process and my
plan is to use a WMI ping to determine if the computer can be accessed
remotely.

narrowing the search to include only non-disabled objects:

* searcher.filter =
"(&(ObjectCate gory=computer)( !UserAccountCon trol:1.2.840.11 3556.1.4.803:=2 ))";

speed

up the search by only selecting the attributes you are interested in:

* searcher.proper tiesToLoad.Add( "cn");
* searcher.proper tiesToLoad.Add( "PwdLastSet ");

I should say at this point I have to calculate the PwdLastSet time
because we are not running a windows 2003 domain in native mode. I
believe in 2k3 the LastLogon time stamp (or something similar) is
replicated to all DCs which will make this method redundant. If you
have a 2k3 domain I would investigate looking for that attribute.
However . . .

. . .Now calculate a suitable cut off period based on the PwdLastSet
attribute

[your routine for itterating through the list of comp objects in the
searchresult s]

* DateTime today = DateTime.Now;
* DateTime cutoff = today.Subtract( new TimeSpan(30,0,0 ,0)); //30 Days
* //I'm not sure if the following line is exactly necessary but I use
it as I need to output a friendly time
* DateTime compPwdLastSet =
DateTime.FromF ileTime((long)c omp.Properties["PwdLastSet "][0]);

* If (compPwdLastSet <= cutoff)
* {
* //object is probably stale
* }

I'd be interested to see what you do with the machines once you have a
list :-)

Cheers,
n


Thanks, that has helped me, but now I have another, very strange
error..
The results it returns are still pretty far wide of the mark.
I used the "LastLogon" Property and filtered out any machines over 30
days ago.
Now its still showing machines that havent been used in months/years.
And some anomalies are cropping up.

It shows the following computer names for example:
10-07
10-07-Vista

Neither of these are now valid machines, however,
When i ping these from a command prompt, they show the same IP
address.
when i ping that IP address with the -a switch to resolve the machine
name, It returns a third, completely different name.
Some PC's are ok, others are not.

This is a network/active directory problem i'm sure. But if anyone
knows why it would do this I would appreciate it.

No simple way to simply reproduce the list from Net View or My Network
Places? Those show the exact results i'm looking for..
This means that you have computers in the directory that no longer exists,
or in other words your Directory is inconsistent.
The directory is a static store, that is, it doesn't reflect the real
situation on the network. You can create a thousands of computers they will
show up even if they don't exists. The Directory does not keep track of the
actual state of a physical computer (or other managed device for that
matter), so you can't use DS to get a list of powered on computers.
What you can do is use a combination of DS and WMI, but this requires at
least a consistent Directory;
use DS to get a list of computers and use WMI to query the state of these
computers, note that this requires WMI to be enabled and accessible
remotely.
Willy.

May 23 '07 #4
On 2007-05-23 12:24:28 +0100, JB <ja*******@gmai l.comsaid:
>>
The way I tackled a similar problem was to first omit any computer
objects that are disabled then calculate the likelyhood of a computer
object being "active" based on the PwdLastSet attribute. This will
narrow your search somewhat but you'll stil run into computers that are
not switched on at that moment in time. Actually, I am planning on
implementing a similar feature such that the results of the
DirectorySearc her can be fed into another interactive process and my
plan is to use a WMI ping to determine if the computer can be accessed
remotely.

narrowing the search to include only non-disabled objects:

* searcher.filter =
"(&(ObjectCate gory=computer)( !UserAccountCon trol:1.2.840.11 3556.1.4.803:=2 ))";

speed

up the search by only selecting the attributes you are interested in:

* searcher.proper tiesToLoad.Add( "cn");
* searcher.proper tiesToLoad.Add( "PwdLastSet ");

I should say at this point I have to calculate the PwdLastSet time
because we are not running a windows 2003 domain in native mode. I
believe in 2k3 the LastLogon time stamp (or something similar) is
replicated to all DCs which will make this method redundant. If you
have a 2k3 domain I would investigate looking for that attribute.
However . . .

. . .Now calculate a suitable cut off period based on the PwdLastSet attribute

[your routine for itterating through the list of comp objects in the
searchresult s]

* DateTime today = DateTime.Now;
* DateTime cutoff = today.Subtract( new TimeSpan(30,0,0 ,0)); //30 Days
* //I'm not sure if the following line is exactly necessary but I use
it as I need to output a friendly time
* DateTime compPwdLastSet =
DateTime.FromF ileTime((long)c omp.Properties["PwdLastSet "][0]);

* If (compPwdLastSet <= cutoff)
* {
* //object is probably stale
* }

I'd be interested to see what you do with the machines once you have a list :-)

Cheers,
n


Thanks, that has helped me, but now I have another, very strange
error..
The results it returns are still pretty far wide of the mark.
I used the "LastLogon" Property and filtered out any machines over 30
days ago.
Now its still showing machines that havent been used in months/years.
And some anomalies are cropping up.

It shows the following computer names for example:
10-07
10-07-Vista

Neither of these are now valid machines, however,
When i ping these from a command prompt, they show the same IP
address.
when i ping that IP address with the -a switch to resolve the machine
name, It returns a third, completely different name.
Some PC's are ok, others are not.

This is a network/active directory problem i'm sure. But if anyone
knows why it would do this I would appreciate it.

No simple way to simply reproduce the list from Net View or My Network
Places? Those show the exact results i'm looking for..
The first thing I would say is make sure your domain is running in
windows 2003 native mode. The LastLogon attribute is not replicated
prior to that so it's completely possible you will pick up stale
results.

When pinging machines with just the host name you need to make sure
your lookup options are doing what you expect them to ie. WINS, DNS and
search order etc. You might also run into situations where hosts are
running NAT locally (say for sandboxing / virtualisation reasons) which
is a potential reason for getting two hosts sharing an IP.

As for running Net View and capturing the output - I couldn't get that
to work consistently on my machine.

You can use System.Diagnost ics.Process to launch and (at least by the
look of it) capture the output stream. I couldn't get that to work at
all.

using System.Diagnost ics;

Process myProc = Process.Start(" net","view");

Good Luck
May 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4556
by: Dirk Hagemann | last post by:
Hi! I'm using this code to list all computers of our WinNT-Domains: import win32com.client from pprint import pprint as p domain='domainX' auswahl='computer' def enumerate(domain,auswahl): adsi = win32com.client.Dispatch("ADsNameSpaces")
1
2686
by: Lloyd Taylor | last post by:
Hello, I have a simple bit of code which I have found in the forums which lists all the computer(s) in a domain. The code is: DirectoryEntry domainEntry = new DirectoryEntry("WinNT://DOMAIN"); domainEntry.Children.SchemaFilter.Add("computer"); foreach(DirectoryEntry server in domainEntry.Children) computers.Add(server.Name);
8
6265
by: Sameh Ahmed | last post by:
Hello there I need to get a list of domain controllers to a domain I bind too using it's name rather than the DN. I am trying a query looking for objectClass=nTDSDSA but this returns 0 results I am using VB.net 2.0 any ideas? Here's my code Thanks in advance.
0
986
by: MAF | last post by:
How can I create a list of domain users and groups?
1
9776
by: MAF | last post by:
How can I create a list of domain users and groups?
16
1469
by: Terry Burns | last post by:
Hi Guys, I know this is a bit off topic, but im not having any luck googling it. I want to know where I can go programatically to get a list of all registered domains on the internet. Cheers
3
4377
by: Jeff Waskiewicz | last post by:
Hello, I think the subject says it all I am trying to return a list of domain names to later display in a combobox. I found a number of VB6 samples that show how to do this using the WNetOpenEnum and WNetEnumResource API calls. I have modified the code to work in VB 2003 but I keep getting a 487 - ERROR_INVALID_ADDRESS error. My envioronment is W2K with a W2003 DC. So I have 2 questions: 1) Is this the best way to do this in .NET?...
12
2889
by: js | last post by:
Hi list, I have a list of URL and I want to sort that list by the domain name. Here, domain name doesn't contain subdomain, or should I say, domain's part of 'www', mail, news and en should be excluded. For example, if the list was the following ------------------------------------------------------------ http://mail.google.com
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.