Important alert: (current site time 7/16/2013 3:18:45 AM EDT)
 

winzip icon

Show all Domains and Computers in LAN

Email
Submitted on: 2/10/2001 7:46:09 AM
By: Mark van Renswoude  
Level: Intermediate
User Rating: By 17 Users
Compatibility: VB 5.0, VB 6.0
Views: 52561
author picture
 
     After searching for this without results for about a year, I put all little bits of code I have found together and created these two Class Modules. One Class Module handles the enumeration of the Domains / Workgroups in your LAN, the other handles the enumeration of the Computers available in a specific domain. Included is a small demonstration program (as shown in the screenshot). Because of the Class Modules, you can easily add this functionality to any other program. This has only been tested on Win98 SE (so it does work on Win98, not like most other examples I have found, they only worked on WinNT). If anyone has problems with the enumeration on certain systems, please let me know so I can work it out. As usual, please leave comments, and vote if you like.

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Show all Domains and Computers in LAN
'**************************************
All in the class modules.
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 7 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/10/2001 9:18:33 AMScott

We have 79 domains here. This code is very slow if there are a lot of network nodes. It might be fine to use on a network with under 100 machines.
(If this comment was disrespectful, please report it.)

 
2/10/2001 9:25:11 AMPowersoft Programming

I don't know if that problem is in my code or not. As far as I can see, there's not much to slow it down in the code itself. This could be slown down by Windows, because it has to find all computers in all domains (which may use a lot of communicating in your network). If you have other programs which do the same faster, then I'm probably wrong. If you know ways of speeding this up (if possible), please let me know too...
(If this comment was disrespectful, please report it.)

 
2/10/2001 11:30:50 AMTim Miron

Yea, i agree with Powersoft, this code works fine on our network, I give ya 5 STARS!
(If this comment was disrespectful, please report it.)

 
2/11/2001 8:31:48 PMAGP

Ive created a VB program that does somehting like this. It finds domains and computers on those domains. It actually does searches for files on the network. It is completely freeware at www.WarpEngine.com. I actually used snippets of code from PlanetSourceCode to make the network engine. You might try my program to see if it could be the code thats slowing it down. Typical use for my program is at LAN parties with more than 300 machines. Im gonna check out PowerSoft's code though cause ive had some minor problems with my code. Always looking to refine my programs and like i said its complete freeware.
(If this comment was disrespectful, please report it.)

 
2/12/2001 3:13:52 AMPlasma

can we get s/c for ya proggie AGP? :D
(If this comment was disrespectful, please report it.)

 
2/12/2001 5:04:28 AMMatrix

I got this error when I run it.
Runtime error 7773
"Could not enumerate computers in domain!

BTW, I'm using windows NT 4.
How can I execute this properly?
(If this comment was disrespectful, please report it.)

 
2/12/2001 6:33:44 AMPowersoft Programming

This is what causing it (Refresh sub in clsComputers):

lReturn = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, tNetRes, lEnumHwnd)

If lReturn <> 0 Then
'// Raise error
Err.Raise 7773, , "Could not enumerate computers in domain!"
Exit Sub
End If

If you comment out the Err.Raise and Exit Sub lines, it goes on without the error, although I doubt if it will function correctly, just try!
(If this comment was disrespectful, please report it.)

 
2/13/2001 12:28:54 AMAGP

Plasma..I cant release the source code right now as some of it is proprietary. However if youre looking for a specific function I might be able to tell you where i found it on PlanetSourceCode.
...
Mark from PowerSoft, my program sometimes errors out to when trying to enumarate computers in a doamin. It seems that some domains have problems opening even when you go to Network Neighborhood and try to open them manually. Trying to open the domains through code has problems too. Another program that does network searches like mine bombs on the same domain so i dont think its the code but rather how the network itself is setup. If you want to talk about it further we can chat offline or continue here for the benefit of other coders.
(If this comment was disrespectful, please report it.)

 
2/13/2001 3:25:42 AMPowersoft Programming

I think that's the problem too, I started this test again when the other PC was changing OS (multi-boot), thus the computers in the domain (workgroup to be specific, using Win98) changed and Windows had to re-initialize it. It took about 15 seconds before the form appeared, so that has definitely something to do with your network.

AGP, I don't think this discussion will last very long: it's just a network problem........ :-)

I think the only solution to this problem would be to either try to retrieve computers from a domain like 5 or 10 times and then stop trying, or don't try at all and just wait until something causes it to refresh (the user or a timer or something).

Btw, my email is changing from the one shown on PSC to: webmaster@psprogramming.virtualave.net (website also changes to: http://psprogramming.virtualave.net), didn't have time to update it yet, but going to very soon.....
(If this comment was disrespectful, please report it.)

 
2/13/2001 12:50:06 PMAGP

Yeah, I agree with you. If something in the network changes then the OS sometimes takes a while to refresh the domains and computers. Although, sometimes at my work LAN there seems to be a
(If this comment was disrespectful, please report it.)

 
2/13/2001 12:54:07 PMEl Mariachi

(hmm.my message was cut off...)
... "bad" node. Even when i go to Net Neighborhood and try to open the node manually there is a windows error. However this node is ALWAYS there. i havent narrowed down why its there nad why its "bad". my program craps out when the file search gets to this node.
My program also enumerates the domains on the fly only when a user clicks on search or when the user wishes to change the starting node of the search.
Anyway, just by browsing thru your code it seems that u do the same stuff as my current code. anyway ill test your classes for efficiency and let u know what happens.
(If this comment was disrespectful, please report it.)

 
2/14/2001 2:01:55 PMAGP

Mark, from doing some testing i found a bug in both your code as well as mine. The enumerator craps out when a computer with the same name apperas in different services. For example, if i put a debug statement at
For lX = 1 To cComputers.GetCount
Debug.Print cDomains.GetItem(lK) & " " & cComputers.GetItem(lX)
tvLAN.Nodes.Add cDomains.GetItem(lK), tvwChild, cComputers.GetItem(lX), cComputers.GetItem(lX), 3
Next lX on my work LAN
then the code craps out if my LAN is setup up as follows:
Novell Directory Services 0000E6U1
Novell Directory Services VPN_TEST
Novell Directory Services WELA
Novell Directory Services YEARK
NetWare Servers 0000E6U1
The error is #35602. I remember a long time ago getting this error but i never fixed it. Any suggestions??

(If this comment was disrespectful, please report it.)

 
2/14/2001 2:32:54 PMAGP

Another thing I found Mark is that it seems like your code somehow skips domains in the root of Network Neighborhood. I ran your code and my code side-by-side on my work LAN and the domains in the root dont show up in your code. I have a pic but i dont know where to put it so ill just email it to you.
(If this comment was disrespectful, please report it.)

 
2/24/2001 6:54:45 PMSJW

It seems to work on Windows ME as well.
(If this comment was disrespectful, please report it.)

 
3/4/2001 12:21:50 AMcarreraj

I got a run-time error 35602

Key is not unique in collection

this part of code ...
For lX = 1 To cComputers.GetCount
tvLAN.Nodes.Add cDomains.GetItem(lK), tvwChild, cComputers.GetItem(lX), cComputers.GetItem(lX), 3
Next lX

what can i do to make your code work?

e-mail me at
carreraj@netscape.net
(If this comment was disrespectful, please report it.)

 
3/4/2001 2:55:18 AMPowersoft Programming

I know that bug is in the code, it's probably because you have 2 computers with the same name in 2 different domains.

The solution: download my update to this code, which solves the treeview problem and adds enumeration of shares resources for computers.

I got an error when trying to upload the update to PSC (some ASP error), if you still want the update before I am able to upload it here, mail me at webmaster@psprogramming.virtualave.net (the code can soon be found on my site too).
(If this comment was disrespectful, please report it.)

 
3/22/2001 12:41:14 PMGPL

Hey AGP, just make sure the code you used from PSC wasnt GPLed, else you'd be forced to reveal all of your source.
(If this comment was disrespectful, please report it.)

 
3/23/2001 1:59:17 AMAnDy2552

Try reducing the TTL for faster response. On the other hand, you won't get a complete list.
(If this comment was disrespectful, please report it.)

 
3/25/2001 6:53:25 PMemj

cant run it in Windows NT (2000). Same error shows as with user of Windows NT 4.0... Comment out the err.raise line wont solve the problem instead will hang. This wont work with Windows NT.
(If this comment was disrespectful, please report it.)

 
3/25/2001 6:54:35 PMchristian

got same error with problems on win nt 4.0. im using win 2000 nt. commenting err.raise line wont solve the problem. it will cause the code to hang.
(If this comment was disrespectful, please report it.)

 
3/26/2001 3:16:53 AMGuus

Have been looking for such functionality for so long. Hope it works. If so, five stars for u!
(If this comment was disrespectful, please report it.)

 
3/27/2001 10:50:24 AMhuntm

This doesn't work on WinNT2k, but it was a good effort from what i see!
(If this comment was disrespectful, please report it.)

 
6/27/2001 5:01:06 AMAndrew Webb

This is great, I'm using it under NT4 and the computers in the domain list fine (although I only use the Computer class. Is there a way to list the computers that would normally be grayed out in server manager as well as the 'live' ones ?
(If this comment was disrespectful, please report it.)

 
6/27/2001 5:01:53 AMAndrew Webb

This works great under NT4 using the computers class. Is there a way to get it to list the computers which would normally be grayed out in server manager, not just the 'live' ones ?
(If this comment was disrespectful, please report it.)

 
7/20/2001 5:32:16 PMTodd

Ok.. lets see if you can answer this tricky one.. do you know how to list the computers that are hidden from the network browser? I can use NetUserEnum (which enumerates the workstation accounts from the SAM database) to get a list of every possible computer name. This is a problem because it can be slow. Any ideas?
(If this comment was disrespectful, please report it.)

 
11/18/2001 10:10:57 PMkarim

First
I got this error when I run
it.
Runtime error 7773

(If this comment was disrespectful, please report it.)

 
11/18/2001 10:20:38 PMkarim

I got this error when I run
it.
Runtime error 7773
"Could not
enumerate computers in domain!
after that accroding Your reason i comment the That two lines and i run the program.
but now sytem is hanging

BTW,
I'm using windows server 2000.
How can I
execute this properly?

(If this comment was disrespectful, please report it.)

 
11/19/2001 3:06:02 AMMark van Renswoude

I stopped using VB, switched to Delphi, so I'm not able to update this code. If there's anyone out there that knows how to correct this code so it works in all cases, you are free to take this code and upload the improved version. All that I'm asking for is a little credit for the original code.
(If this comment was disrespectful, please report it.)

 
12/31/2001 2:36:36 PMChris

Here's what I figured out. This code has problems with Win2k (and subsequently, WinXP) because the Refresh sub checks the stuff it grabs from
(If this comment was disrespectful, please report it.)

 
2/27/2002 12:24:10 AMJamie Lindgren

Yep... I got WinXP and it doesn't work -_-
(If this comment was disrespectful, please report it.)

 
8/26/2002 11:21:11 AM_maniac_

the prob with it not working in any form of NT is probably that NT has completely different network stuff...
(If this comment was disrespectful, please report it.)

 
3/6/2003 11:10:49 PMCollin_F

Does not work at all on XP, Total memory leak
(If this comment was disrespectful, please report it.)

 
9/27/2003 12:22:39 AM

Repl: order
(If this comment was disrespectful, please report it.)

 
7/24/2004 1:30:58 AM

I tried it on windows 2000(nt) but i m getting error!

(If this comment was disrespectful, please report it.)

 
7/24/2004 1:33:17 AM

This is a great job.
But it is not woking in windows2000
giving an error "cannot enumerate computers in domain!"
suggest enhance ments if available
(If this comment was disrespectful, please report it.)

 
7/24/2004 1:37:53 AM

Yes'B
This is a great job.
i found only entry/posting in the net on this task.
But it is not
woking in windows2000
giving an error
"cannot enumerate computers in
domain!"
suggest enhance ments if
available

(If this comment was disrespectful, please report it.)

 
9/27/2004 8:14:13 AM

it is not woking on windows2000 Server &
giving an error "cannot enumerate computers in domain!". can i correct this situation?

(If this comment was disrespectful, please report it.)

 
3/10/2005 12:50:06 AMIT_proff2004

hello nice code but not working with windows 2000 server so please check it if u can modify great work thanks
(If this comment was disrespectful, please report it.)

 
6/16/2005 2:25:03 AM

This is a good code. It run well in window98. But it is not woking in windows2000, giving an error "cannot
enumerate computers in domain!"
Can you show me how to repair it ??
(If this comment was disrespectful, please report it.)

 
12/7/2005 3:28:52 AMWilliam Pickering

Does not seem to work on Win XP. Gives "Cannot enumerate computers in domain" error. It appears to be that it is not enumerating the actual domains though. My domain at home is MSHOME & this code picks up "Microsoft Terminal Services", "Microsoft Windows Network" and "Web Client Network".
Hope this helps in solving the problem.
(If this comment was disrespectful, please report it.)

 
3/12/2007 4:22:34 AMKiran

I was used "Show all Domains and Computers in LAN". Code was working fine. But I have problemed that when i used this code my network connection is lost & again i can't use this code. I have to close the application & then my network connection is working. Please Suggest how to solve this problem.
(If this comment was disrespectful, please report it.)

 
2/4/2009 6:21:20 AMmoe min han

this program not run in my computer

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.