473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

List of Computers on Network

Hi all

How would i get a list of all Active Computers on a network? All I need are
the computer names.

Kind Regards,
Steve.
Nov 20 '05 #1
3 3847
Hi,

This will only work if you are connected to an active directory. Add
a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")

Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToStrin g)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries,
_

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup
name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module

Ken
---------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
Hi all

How would i get a list of all Active Computers on a network? All I need are the computer names.

Kind Regards,
Steve.

Nov 20 '05 #2
Hi Ken

Thanks for that!

I was hoping to just get a list of active computers, this method lists all
computers even if they're not currently connected to the network. It's not
important that I get it perfect, I could do some more work to try to
establish this but I'm not too fussed.

I appreciate your help.

Kind Regards,
Steve.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
Hi,

This will only work if you are connected to an active directory. Add a reference to system.directoryservices. Replace NetworkName with your
network name.

Dim de As New System.DirectoryServices.DirectoryEntry("LDAP://NetworkName")
Dim ds As New System.DirectoryServices.DirectorySearcher(de)

Dim r As System.DirectoryServices.SearchResult

ds.Filter = "(objectClass=computer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLine(r.GetDirectoryEntry.Name.ToStrin g)

Next

Catch e As Exception

Console.WriteLine(e.ToString)

End Try
This NetServerEnum api will work for a network without a domain. I
pasted the code for a sample console app below.

Imports System.Runtime.InteropServices

Module Module1

Structure Computer_info_101

Public Platform_ID As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttribute(UnmanagedType.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.dll" _

(ByVal Servername As Integer, ByVal level As Integer, _

ByRef buffer As Integer, ByVal PrefMaxLen As Integer, _

ByRef EntriesRead As Integer, ByRef TotalEntries As Integer, _

ByVal ServerType As Integer, ByVal DomainName As String, _

ByRef ResumeHandle As Integer) As Integer

Declare Function NetApiBufferFree Lib "Netapi32.dll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_101

Dim i, MaxLenPref, level, ret, EntriesRead, TotalEntries, ResumeHandle As
Integer

Dim BufPtr As Integer

Dim iPtr As IntPtr

MaxLenPref = -1

level = 101

ret = NetServerEnum(0, level, BufPtr, MaxLenPref, EntriesRead, TotalEntries, _

SV_TYPE_SERVER, "MSHOME", ResumeHandle) ' Replace MSHOME with your workgroup name

If ret <> 0 Then

Console.WriteLine("An Error has occured")

Return

End If

' loop thru the entries

For i = 0 To EntriesRead - 1

' copy the stuff into our structure

Dim ptr As IntPtr = New IntPtr(BufPtr)

computerInfo = CType(Marshal.PtrToStructure(ptr,
GetType(Computer_info_101)), _

Computer_info_101)

BufPtr = BufPtr + Len(ComputerInfo)

Console.WriteLine(computerInfo.Name)

Next

NetApiBufferFree(BufPtr)

Console.Write("Press Enter to End")

Dim s As String = Console.ReadLine()

End Sub

End Module

Ken
---------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message
news:eS**************@TK2MSFTNGP11.phx.gbl...
Hi all

How would i get a list of all Active Computers on a network? All I need

are
the computer names.

Kind Regards,
Steve.


Nov 20 '05 #3

Nov 20 '05 #4

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

Similar topics

10
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network...
0
by: Oshadha | last post by:
Hi All I'm trying to query and get a list of all reachable computers in a network. I also heard that you can query active directory and find domain pc list. but my need is not to query active...
3
by: newsgroups.jd | last post by:
Im sure there is a better way to do this - just posting what I did to get it to work. Please feel free to comment with suggestions - this was my first vb.net program and I am not a programmer,...
0
by: NoWhereMan | last post by:
Hello, I'm trying to get the list of shared folders of a network computer and add them to a combo box. I'm using the bellow code in VB .NET. Code ==== Private Sub EnumShares(ByVal Machine As...
4
by: JB | last post by:
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...
6
by: kimiraikkonen | last post by:
Hello, I've been working on a project and i wonder how to get list of the LAN computer names in a tree list which are involved under the same workgroup name? What can be the code be? Very...
11
by: jellychai | last post by:
I'm doing the final year project that related to the SNMP. I need to find the solution for the IP auto detection in C#. When I run the main project, the program can automatically detect the IP for...
17
by: John Salerno | last post by:
Let me see if this question even makes sense...I'm reading Core Python Programming and I jumped ahead to the more specific topics like network programming. I plan to follow along with the example...
6
by: belias | last post by:
So...here we go. I'm having an issue with one computer on a network not being able to ping other computers by name. I've spent the last day searching similar issues and I've tried all the steps...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.