473,399 Members | 3,888 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,399 software developers and data experts.

Enumerating machines on domain network

Hi - I found the class below on another website (www.devx.com)
and can't seem to figure out how to make a call to this class to
retrieve the machines and put them in a listbox.

I am definitely a beginner in vb programming, and would really
appreciate the help.

TIA!

Imports System.Runtime.InteropServices

Public Class MasterBrowseList

Private Const MAX_PREFERRED_LENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000
'Windows95 +
Private Const SV_TYPE_DFS As Long = &H800000
'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT
Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000
'return local only
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Const SV_TYPE_ALL As Long = &HFFFFFFFF
Private Const MAJOR_VERSION_MASK As Long = &HF

Private Structure SERVER_INFO_101
Dim PlatformID As Integer
Dim Name As IntPtr
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim Type As Integer
Dim Comment As IntPtr
End Structure

Private Declare Auto Function NetApiBufferFree Lib "netapi32.dll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.dll" _
(ByVal nullptr As Integer, _
ByVal Level As Integer, _
ByRef BufPtr As IntPtr, _
ByVal BufMaxLen As Integer, _
ByRef EntriesRead As Integer,
_
ByRef TotalEntries As Integer,
_
ByVal ServerType As Integer, _
ByVal Domain As IntPtr, _
ByVal ResumeHandle As Integer)
As Integer
Public Enum MACHINEPLATFORM As Integer
DOS = 300
OS2 = 400
NT_2K_XP = 500
OSF = 600
VMS = 700
End Enum

Public Enum MACHINETYPE As Integer
Workstation = &H1
Server = &H2
SQLServer = &H4
DomainController = &H8
BackupDomainController = &H10
TimeSource = &H20
AppleFileProtocolServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroups = &H2000
ServerFilePrintForNetware = &H4000
ServerNT = &H8000
PotentialBrowser = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigher = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualServer = &H4000000
End Enum

Public Structure MACHINE
Dim Platform As MACHINEPLATFORM
Dim Name As String
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim TypeBits As MACHINETYPE
Dim Comment As String
End Structure

Public Shared Function GetMasterBrowseList() As MACHINE()
Return GetMasterBrowseList(Nothing)
End Function

Public Shared Function GetMasterBrowseList(ByVal Domain As String)
As MACHINE()
Dim BrowseList As New ArrayList

Dim BufPtr As IntPtr
Dim se101 As SERVER_INFO_101
Dim StructSize As Integer = Marshal.SizeOf(se101)

Dim EntriesRead As Integer
Dim TotalEntries As Integer
Dim ServerType As Integer = SV_TYPE_WORKSTATION Or
SV_TYPE_SERVER
Dim DomainPtr As IntPtr

If Domain Is Nothing Or Domain = "" Then
DomainPtr = New IntPtr(0)
Else
'we are faking a constant string here with a BSTR by
appending
'a null character. we'll free it afterwards
DomainPtr = Marshal.StringToBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0, _
101, _
BufPtr, _
MAX_PREFERRED_LENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBSTR(DomainPtr)

Try
If ret = NERR_SUCCESS Then
Dim nextbufptr As IntPtr

For t As Integer = 0 To EntriesRead - 1
'copy memory chunk OF SIZE StructSize
' FROM LOC bufptr +
(StructSize + t)
' INTO LOC se101
nextbufptr = New IntPtr(BufPtr.ToInt32 +
(StructSize * t))
se101 = Marshal.PtrToStructure(nextbufptr,
GetType(SERVER_INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToStringUni(se101.Name)
themachine.Comment =
Marshal.PtrToStringUni(se101.Comment)
themachine.Platform = se101.PlatformID
themachine.TypeBits = se101.Type
themachine.VersionMajor = se101.VersionMajor And
MAJOR_VERSION_MASK
themachine.VersionMinor = se101.VersionMinor

BrowseList.Add(themachine)
Next
End If
Catch ex As Exception
Throw ex
Finally
NetApiBufferFree(BufPtr)
End Try

Return BrowseList.ToArray(GetType(MACHINE))

End Function

End Class
Nov 21 '05 #1
3 2761
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
---------------

"Joe User" <ja*********@yahoo.com> wrote in message
news:a2**************************@posting.google.c om...
Hi - I found the class below on another website (www.devx.com)
and can't seem to figure out how to make a call to this class to
retrieve the machines and put them in a listbox.

I am definitely a beginner in vb programming, and would really
appreciate the help.

TIA!

Imports System.Runtime.InteropServices

Public Class MasterBrowseList

Private Const MAX_PREFERRED_LENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000
'Windows95 +
Private Const SV_TYPE_DFS As Long = &H800000
'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT
Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000
'return local only
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Const SV_TYPE_ALL As Long = &HFFFFFFFF
Private Const MAJOR_VERSION_MASK As Long = &HF

Private Structure SERVER_INFO_101
Dim PlatformID As Integer
Dim Name As IntPtr
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim Type As Integer
Dim Comment As IntPtr
End Structure

Private Declare Auto Function NetApiBufferFree Lib "netapi32.dll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.dll" _
(ByVal nullptr As Integer, _
ByVal Level As Integer, _
ByRef BufPtr As IntPtr, _
ByVal BufMaxLen As Integer, _
ByRef EntriesRead As Integer,
_
ByRef TotalEntries As Integer,
_
ByVal ServerType As Integer, _
ByVal Domain As IntPtr, _
ByVal ResumeHandle As Integer)
As Integer
Public Enum MACHINEPLATFORM As Integer
DOS = 300
OS2 = 400
NT_2K_XP = 500
OSF = 600
VMS = 700
End Enum

Public Enum MACHINETYPE As Integer
Workstation = &H1
Server = &H2
SQLServer = &H4
DomainController = &H8
BackupDomainController = &H10
TimeSource = &H20
AppleFileProtocolServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroups = &H2000
ServerFilePrintForNetware = &H4000
ServerNT = &H8000
PotentialBrowser = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigher = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualServer = &H4000000
End Enum

Public Structure MACHINE
Dim Platform As MACHINEPLATFORM
Dim Name As String
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim TypeBits As MACHINETYPE
Dim Comment As String
End Structure

Public Shared Function GetMasterBrowseList() As MACHINE()
Return GetMasterBrowseList(Nothing)
End Function

Public Shared Function GetMasterBrowseList(ByVal Domain As String)
As MACHINE()
Dim BrowseList As New ArrayList

Dim BufPtr As IntPtr
Dim se101 As SERVER_INFO_101
Dim StructSize As Integer = Marshal.SizeOf(se101)

Dim EntriesRead As Integer
Dim TotalEntries As Integer
Dim ServerType As Integer = SV_TYPE_WORKSTATION Or
SV_TYPE_SERVER
Dim DomainPtr As IntPtr

If Domain Is Nothing Or Domain = "" Then
DomainPtr = New IntPtr(0)
Else
'we are faking a constant string here with a BSTR by
appending
'a null character. we'll free it afterwards
DomainPtr = Marshal.StringToBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0, _
101, _
BufPtr, _
MAX_PREFERRED_LENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBSTR(DomainPtr)

Try
If ret = NERR_SUCCESS Then
Dim nextbufptr As IntPtr

For t As Integer = 0 To EntriesRead - 1
'copy memory chunk OF SIZE StructSize
' FROM LOC bufptr +
(StructSize + t)
' INTO LOC se101
nextbufptr = New IntPtr(BufPtr.ToInt32 +
(StructSize * t))
se101 = Marshal.PtrToStructure(nextbufptr,
GetType(SERVER_INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToStringUni(se101.Name)
themachine.Comment =
Marshal.PtrToStringUni(se101.Comment)
themachine.Platform = se101.PlatformID
themachine.TypeBits = se101.Type
themachine.VersionMajor = se101.VersionMajor And
MAJOR_VERSION_MASK
themachine.VersionMinor = se101.VersionMinor

BrowseList.Add(themachine)
Next
End If
Catch ex As Exception
Throw ex
Finally
NetApiBufferFree(BufPtr)
End Try

Return BrowseList.ToArray(GetType(MACHINE))

End Function

End Class
Nov 21 '05 #2
Thanks for the post Ken, but I'm not working in an AD environment
'yet'. Seems like it'd be easier if i was. :\

I'll take a look at the console code, but I was hoping someone could
show me how to use the code i posted, as I'd really like to know how
the function GetMasterBrowseList is to be used and what exactly it
returns.

Any ideas?
Thanks again!

joe

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:<ex**************@TK2MSFTNGP09.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
---------------

"Joe User" <ja*********@yahoo.com> wrote in message
news:a2**************************@posting.google.c om...
Hi - I found the class below on another website (www.devx.com)
and can't seem to figure out how to make a call to this class to
retrieve the machines and put them in a listbox.

I am definitely a beginner in vb programming, and would really
appreciate the help.

TIA!

Imports System.Runtime.InteropServices

Public Class MasterBrowseList

Private Const MAX_PREFERRED_LENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long = SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long = &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long = &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long = &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long = &H80000
Private Const SV_TYPE_SERVER_OSF As Long = &H100000
Private Const SV_TYPE_SERVER_VMS As Long = &H200000
Private Const SV_TYPE_WINDOWS As Long = &H400000
'Windows95 +
Private Const SV_TYPE_DFS As Long = &H800000
'Root of a DFS tree
Private Const SV_TYPE_CLUSTER_NT As Long = &H1000000 'NT
Cluster
Private Const SV_TYPE_TERMINALSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNATE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long = &H40000000
'return local only
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Const SV_TYPE_ALL As Long = &HFFFFFFFF
Private Const MAJOR_VERSION_MASK As Long = &HF

Private Structure SERVER_INFO_101
Dim PlatformID As Integer
Dim Name As IntPtr
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim Type As Integer
Dim Comment As IntPtr
End Structure

Private Declare Auto Function NetApiBufferFree Lib "netapi32.dll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.dll" _
(ByVal nullptr As Integer, _
ByVal Level As Integer, _
ByRef BufPtr As IntPtr, _
ByVal BufMaxLen As Integer, _
ByRef EntriesRead As Integer,
_
ByRef TotalEntries As Integer,
_
ByVal ServerType As Integer, _
ByVal Domain As IntPtr, _
ByVal ResumeHandle As Integer)
As Integer
Public Enum MACHINEPLATFORM As Integer
DOS = 300
OS2 = 400
NT_2K_XP = 500
OSF = 600
VMS = 700
End Enum

Public Enum MACHINETYPE As Integer
Workstation = &H1
Server = &H2
SQLServer = &H4
DomainController = &H8
BackupDomainController = &H10
TimeSource = &H20
AppleFileProtocolServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroups = &H2000
ServerFilePrintForNetware = &H4000
ServerNT = &H8000
PotentialBrowser = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigher = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualServer = &H4000000
End Enum

Public Structure MACHINE
Dim Platform As MACHINEPLATFORM
Dim Name As String
Dim VersionMajor As Integer
Dim VersionMinor As Integer
Dim TypeBits As MACHINETYPE
Dim Comment As String
End Structure

Public Shared Function GetMasterBrowseList() As MACHINE()
Return GetMasterBrowseList(Nothing)
End Function

Public Shared Function GetMasterBrowseList(ByVal Domain As String)
As MACHINE()
Dim BrowseList As New ArrayList

Dim BufPtr As IntPtr
Dim se101 As SERVER_INFO_101
Dim StructSize As Integer = Marshal.SizeOf(se101)

Dim EntriesRead As Integer
Dim TotalEntries As Integer
Dim ServerType As Integer = SV_TYPE_WORKSTATION Or
SV_TYPE_SERVER
Dim DomainPtr As IntPtr

If Domain Is Nothing Or Domain = "" Then
DomainPtr = New IntPtr(0)
Else
'we are faking a constant string here with a BSTR by
appending
'a null character. we'll free it afterwards
DomainPtr = Marshal.StringToBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0, _
101, _
BufPtr, _
MAX_PREFERRED_LENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBSTR(DomainPtr)

Try
If ret = NERR_SUCCESS Then
Dim nextbufptr As IntPtr

For t As Integer = 0 To EntriesRead - 1
'copy memory chunk OF SIZE StructSize
' FROM LOC bufptr +
(StructSize + t)
' INTO LOC se101
nextbufptr = New IntPtr(BufPtr.ToInt32 +
(StructSize * t))
se101 = Marshal.PtrToStructure(nextbufptr,
GetType(SERVER_INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToStringUni(se101.Name)
themachine.Comment =
Marshal.PtrToStringUni(se101.Comment)
themachine.Platform = se101.PlatformID
themachine.TypeBits = se101.Type
themachine.VersionMajor = se101.VersionMajor And
MAJOR_VERSION_MASK
themachine.VersionMinor = se101.VersionMinor

BrowseList.Add(themachine)
Next
End If
Catch ex As Exception
Throw ex
Finally
NetApiBufferFree(BufPtr)
End Try

Return BrowseList.ToArray(GetType(MACHINE))

End Function

End Class

Nov 21 '05 #3
Try this:

dim oMasterBrowseList as New MasterBrowseList.GetMasterBrowseList()
dim oMachine as MasterBrowseList.MACHINE

For Each oMachine in oMasterBrowseList
List1.Additem oMachine.Name
Next
From http://developmentnow.com/g/38_2004_...in-network.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 21 '05 #4

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

Similar topics

7
by: Rohan Ranade | last post by:
I am trying to implement a crawler in C# that scans all the shared folders in remote computers in a windows network. Are there classes in .NET to do this directly? Please help. Thank You. Rohan
4
by: Jonny | last post by:
I'm sure this is easy and i'll kick myself for it. How would i go about listing all the machines on a domain? I want to display them in a list box. Thanks /Jonny
6
by: Michael C | last post by:
Hi all, I am currently using a Win32 API call to NetServerEnum to enumerate all SQL Servers on an NT Domain. The function returns the names of all servers running SQL Server on the network, but...
0
by: Michael C | last post by:
Hi all, After a lot of research, I've come to some realizations about enumerating Named Instances of MSDE. NetServerEnum() Win32 API function doesn't work, SQL-DMO doesn't work, no standard...
4
by: Dan Walls | last post by:
Hi, I am deploying an ASP.Net web app into the following scenario: Internet --> Firewall --> WebServer (IIS) --> --> However I am not sure what sort of authentication options are available...
1
by: Robert Fitzpatrick | last post by:
Hello, I'm looking for code examples that displays all the machines in a domain/workgroup using VB.NET. I've seen a few postings on the net on how to do this in VB6, but these will not work...
1
by: Roger | last post by:
I would like to get a list of machines on my network (Workstations and/or Servers). Is there a way to do this in VB.Net? Thanks, Rog
5
by: =?Utf-8?B?Um9nZXI=?= | last post by:
Hello ! My question is simple: How can I change ALL THE PCS ON A DOMAIN to have CAS full trust to a network share ? Notes: When you deploy an application to a network share, as all the...
1
by: twazok | last post by:
Please help I am new to VB and only very rarely use it to create useful tools. i am trying to write an app that needs to build a list of computer names into an array for every machine currently...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.