473,799 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MasterBrowseLis t

Private Const MAX_PREFERRED_L ENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTA TION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERV ER 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_SO URCE 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_S ERVER As Long = &H800
Private Const SV_TYPE_SERVER_ UNIX As Long = SV_TYPE_XENIX_S ERVER
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_POTENTI AL_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_TERMINA LSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNA TE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_L IST_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_M ASK 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 NetApiBufferFre e Lib "netapi32.d ll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.d ll" _
(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
DomainControlle r = &H8
BackupDomainCon troller = &H10
TimeSource = &H20
AppleFileProtoc olServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroup s = &H2000
ServerFilePrint ForNetware = &H4000
ServerNT = &H8000
PotentialBrowse r = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigh er = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualS erver = &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 GetMasterBrowse List() As MACHINE()
Return GetMasterBrowse List(Nothing)
End Function

Public Shared Function GetMasterBrowse List(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_WORKSTA TION 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.StringT oBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0 , _
101, _
BufPtr, _
MAX_PREFERRED_L ENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBST R(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.T oInt32 +
(StructSize * t))
se101 = Marshal.PtrToSt ructure(nextbuf ptr,
GetType(SERVER_ INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToSt ringUni(se101.N ame)
themachine.Comm ent =
Marshal.PtrToSt ringUni(se101.C omment)
themachine.Plat form = se101.PlatformI D
themachine.Type Bits = se101.Type
themachine.Vers ionMajor = se101.VersionMa jor And
MAJOR_VERSION_M ASK
themachine.Vers ionMinor = se101.VersionMi nor

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

Return BrowseList.ToAr ray(GetType(MAC HINE))

End Function

End Class
Nov 21 '05 #1
3 2775
Hi,

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

Dim de As New System.Director yServices.Direc toryEntry("LDAP ://NetworkName")

Dim ds As New System.Director yServices.Direc torySearcher(de )

Dim r As System.Director yServices.Searc hResult

ds.Filter = "(objectClass=c omputer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLi ne(r.GetDirecto ryEntry.Name.To String)

Next

Catch e As Exception

Console.WriteLi ne(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_1 01

Public Platform_ID As Integer

<MarshalAsAttri bute(UnmanagedT ype.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttri bute(UnmanagedT ype.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.d ll" _

(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 NetApiBufferFre e Lib "Netapi32.d ll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_1 01

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.WriteLi ne("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.P trToStructure(p tr,
GetType(Compute r_info_101)), _

Computer_info_1 01)

BufPtr = BufPtr + Len(ComputerInf o)

Console.WriteLi ne(computerInfo .Name)

Next

NetApiBufferFre e(BufPtr)

Console.Write(" Press Enter to End")

Dim s As String = Console.ReadLin e()

End Sub

End Module

Ken
---------------

"Joe User" <ja*********@ya hoo.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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 MasterBrowseLis t

Private Const MAX_PREFERRED_L ENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTA TION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERV ER 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_SO URCE 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_S ERVER As Long = &H800
Private Const SV_TYPE_SERVER_ UNIX As Long = SV_TYPE_XENIX_S ERVER
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_POTENTI AL_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_TERMINA LSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNA TE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_L IST_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_M ASK 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 NetApiBufferFre e Lib "netapi32.d ll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.d ll" _
(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
DomainControlle r = &H8
BackupDomainCon troller = &H10
TimeSource = &H20
AppleFileProtoc olServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroup s = &H2000
ServerFilePrint ForNetware = &H4000
ServerNT = &H8000
PotentialBrowse r = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigh er = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualS erver = &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 GetMasterBrowse List() As MACHINE()
Return GetMasterBrowse List(Nothing)
End Function

Public Shared Function GetMasterBrowse List(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_WORKSTA TION 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.StringT oBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0 , _
101, _
BufPtr, _
MAX_PREFERRED_L ENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBST R(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.T oInt32 +
(StructSize * t))
se101 = Marshal.PtrToSt ructure(nextbuf ptr,
GetType(SERVER_ INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToSt ringUni(se101.N ame)
themachine.Comm ent =
Marshal.PtrToSt ringUni(se101.C omment)
themachine.Plat form = se101.PlatformI D
themachine.Type Bits = se101.Type
themachine.Vers ionMajor = se101.VersionMa jor And
MAJOR_VERSION_M ASK
themachine.Vers ionMinor = se101.VersionMi nor

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

Return BrowseList.ToAr ray(GetType(MAC HINE))

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 GetMasterBrowse List is to be used and what exactly it
returns.

Any ideas?
Thanks again!

joe

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message news:<ex******* *******@TK2MSFT NGP09.phx.gbl>. ..
Hi,

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

Dim de As New System.Director yServices.Direc toryEntry("LDAP ://NetworkName")

Dim ds As New System.Director yServices.Direc torySearcher(de )

Dim r As System.Director yServices.Searc hResult

ds.Filter = "(objectClass=c omputer)"

Try

For Each r In ds.FindAll

Dim s As String

Console.WriteLi ne(r.GetDirecto ryEntry.Name.To String)

Next

Catch e As Exception

Console.WriteLi ne(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_1 01

Public Platform_ID As Integer

<MarshalAsAttri bute(UnmanagedT ype.LPWStr)> Public Name As String

Public Version_Major As Integer

Public Version_Minor As Integer

Public Type As Integer

<MarshalAsAttri bute(UnmanagedT ype.LPWStr)> Public Comment As String

End Structure

Declare Unicode Function NetServerEnum Lib "Netapi32.d ll" _

(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 NetApiBufferFre e Lib "Netapi32.d ll" _

(ByVal lpBuffer As Integer) As Integer

Private Const SV_TYPE_SERVER As Integer = &H2 ' All Servers

Sub Main()

Dim ComputerInfo As Computer_info_1 01

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.WriteLi ne("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.P trToStructure(p tr,
GetType(Compute r_info_101)), _

Computer_info_1 01)

BufPtr = BufPtr + Len(ComputerInf o)

Console.WriteLi ne(computerInfo .Name)

Next

NetApiBufferFre e(BufPtr)

Console.Write(" Press Enter to End")

Dim s As String = Console.ReadLin e()

End Sub

End Module

Ken
---------------

"Joe User" <ja*********@ya hoo.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
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 MasterBrowseLis t

Private Const MAX_PREFERRED_L ENGTH As Integer = -1&
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_WORKSTA TION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERV ER 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_SO URCE 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_S ERVER As Long = &H800
Private Const SV_TYPE_SERVER_ UNIX As Long = SV_TYPE_XENIX_S ERVER
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_POTENTI AL_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_TERMINA LSERVER As Long = &H2000000
'Terminal Server
Private Const SV_TYPE_DCE As Long = &H10000000 'IBM
DSS
Private Const SV_TYPE_ALTERNA TE_XPORT As Long = &H20000000
'return alternate transport
Private Const SV_TYPE_LOCAL_L IST_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_M ASK 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 NetApiBufferFre e Lib "netapi32.d ll"
(ByVal bufptr As IntPtr) As Integer
Private Declare Auto Function NetServerEnum Lib "netapi32.d ll" _
(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
DomainControlle r = &H8
BackupDomainCon troller = &H10
TimeSource = &H20
AppleFileProtoc olServer = &H40
NovellServer = &H80
DomainMember = &H100
PrintServer = &H200
DialinServer = &H400
UnixOrXenix = &H800
NT_2K_XP = &H1000
WinForWorkgroup s = &H2000
ServerFilePrint ForNetware = &H4000
ServerNT = &H8000
PotentialBrowse r = &H10000
BackupBrowser = &H20000
MasterBrowser = &H40000
DomainMaster = &H80000
ServerOSF = &H100000
ServerVMS = &H200000
Windows95OrHigh er = &H400000
DFSRoot = &H800000
ClusterNode = &H1000000
TerminalServer = &H2000000
ClusterVirtualS erver = &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 GetMasterBrowse List() As MACHINE()
Return GetMasterBrowse List(Nothing)
End Function

Public Shared Function GetMasterBrowse List(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_WORKSTA TION 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.StringT oBSTR(Domain & Chr(0))
End If

Dim ret As Integer = NetServerEnum(0 , _
101, _
BufPtr, _
MAX_PREFERRED_L ENGTH, _
EntriesRead, _
TotalEntries, _
ServerType, _
DomainPtr, _
0)
Marshal.FreeBST R(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.T oInt32 +
(StructSize * t))
se101 = Marshal.PtrToSt ructure(nextbuf ptr,
GetType(SERVER_ INFO_101))

Dim themachine As MACHINE
themachine.Name =
Marshal.PtrToSt ringUni(se101.N ame)
themachine.Comm ent =
Marshal.PtrToSt ringUni(se101.C omment)
themachine.Plat form = se101.PlatformI D
themachine.Type Bits = se101.Type
themachine.Vers ionMajor = se101.VersionMa jor And
MAJOR_VERSION_M ASK
themachine.Vers ionMinor = se101.VersionMi nor

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

Return BrowseList.ToAr ray(GetType(MAC HINE))

End Function

End Class

Nov 21 '05 #3
Try this:

dim oMasterBrowseLi st as New MasterBrowseLis t.GetMasterBrow seList()
dim oMachine as MasterBrowseLis t.MACHINE

For Each oMachine in oMasterBrowseLi st
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
3168
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
1942
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
5447
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 it doesn't return any SQL Server/MSDE named instances. Does anyone have any ideas on how to enumerate all named instances of SQL Server/MSDE on a Domain as well as the default instances? Thanks, Michael C.
0
1277
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 routines seem to work. SQL-DMO is by far the most robust solution - since it calls NetServerEnum() first, and subsequently sends out a broadcast on Port 1433 to locate all SQL Servers on the network. This does pick up all default instances (as long...
4
1687
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 to me in gettingthe application to talk to the SQL server. How do I talk between the web app and the database server - if TCP/IP then
1
1150
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 for us. Thanks RF
1
4606
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
2809
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 pcs have
1
1571
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 on on my network. i do not want to do a directory lookup as this brings up machines curretly off as well. i want the VB equivalent if possible of doing a Net View in dos. Would anyone be able to help - please.......? Many thanks
0
9687
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
9541
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
10484
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...
1
10228
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
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
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();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.