Hi,
You will have to use the api to get that info. Here is a sample
console app.
Imports System.Runtime. InteropServices
Module Module1
Private Const ERROR_SUCCESS = 0&
Private Const FORMAT_MESSAGE_ ALLOCATE_BUFFER As Short = &H100S
Private Const FORMAT_MESSAGE_ FROM_SYSTEM As Short = &H1000S
Private Const LANG_NEUTRAL As Short = &H0S
Private Const SUBLANG_DEFAULT As Short = &H1S
Private Const GMEM_FIXED As Short = &H0S
Private Const GMEM_ZEROINIT As Short = &H40S
Private Const GPTR As Short = (GMEM_FIXED Or GMEM_ZEROINIT)
Private Const LEVEL_NETWORK As Short = 1
Private Const LEVEL_DOMAIN As Short = 2
Private Const LEVEL_SERVER As Short = 3
Private Const LEVEL_SHARE As Short = 4
Private Const LEVEL_DIRECTORY As Short = 5
Private Const LEVEL_FILE As Short = 6
Private Const RESOURCE_CONNEC TED As Short = &H1S
Private Const RESOURCE_GLOBAL NET As Short = &H2S
Private Const RESOURCE_REMEMB ERED As Short = &H3S
Private Const RESOURCETYPE_AN Y As Short = &H0S
Private Const RESOURCETYPE_DI SK As Short = &H1S
Private Const RESOURCETYPE_PR INT As Short = &H2S
Private Const RESOURCETYPE_UN KNOWN As Short = &HFFFFS
Private Const RESOURCEUSAGE_C ONNECTABLE As Short = &H1S
Private Const RESOURCEUSAGE_C ONTAINER As Short = &H2S
Private Const RESOURCEUSAGE_R ESERVED As Integer = &H80000000
Private Const RESOURCEDISPLAY TYPE_GENERIC As Short = &H0S
Private Const RESOURCEDISPLAY TYPE_DOMAIN As Short = &H1S
Private Const RESOURCEDISPLAY TYPE_SERVER As Short = &H2S
Private Const RESOURCEDISPLAY TYPE_SHARE As Short = &H3S
Private Const RESOURCEDISPLAY TYPE_FILE As Short = &H4S
Private Const RESOURCEDISPLAY TYPE_GROUP As Short = &H5S
Private Const RESOURCEDISPLAY TYPE_NETWORK As Short = &H6S
Private Const RESOURCEDISPLAY TYPE_ROOT As Short = &H7S
Private Const RESOURCEDISPLAY TYPE_ADMINSHARE As Short = &H8S
Private Const RESOURCEDISPLAY TYPE_DIRECTORY As Short = &H9S
Private Declare Function GetLastError Lib "kernel32" () As Integer
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA "
_
(ByVal dwFlags As Integer, ByRef lpSource As Object, ByVal dwMessageId As
Integer, _
ByVal dwLanguageId As Integer, ByVal lpBuffer As String, ByVal nSize As
Integer, _
ByRef Arguments As Integer) As Integer
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 Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As
Integer, _
ByVal dwBytes As Integer) As Integer
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Integer)
As Integer
Private Declare Function WNetGetLastErro r Lib "mpr.dll" Alias
"WNetGetLastErr orA" _
(ByRef lpError As Integer, ByVal lpErrorBuf As String, _
ByVal nErrorBufSize As Integer, ByVal lpNameBuf As String, _
ByVal nNameBufSize As Integer) As Integer
Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEn umA" _
(ByVal dwScope As Integer, ByVal dwType As Integer, ByVal dwUsage As
Integer, _
ByRef lpNetResource As NETRESOURCE, ByRef lphEnum As Integer) As Integer
Private Declare Function WNetEnumResourc e Lib "mpr.dll" Alias
"WNetEnumResour ceA" _
(ByVal hEnum As Integer, ByRef lpcCount As Integer, ByVal lpBuffer As
Integer, _
ByRef lpBufferSize As Integer) As Integer
Private Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As
Integer) As Integer
Private Structure NETRESOURCE
Dim dwScope As Integer
Dim dwType As Integer
Dim dwDisplayType As Integer
Dim dwUsage As Integer
Dim lpLocalName As Integer
Dim lpRemoteName As Integer
Dim lpComment As Integer
Dim lpProvider As Integer
End Structure
Private m_strNetworkNam e As String
Sub Main()
Dim lngEnumHandle As Integer
Dim nrInit As NETRESOURCE
lngEnumHandle = GetNetworkHandl e(nrInit, True)
If lngEnumHandle = 0 Then
Console.WriteLi ne("No network.")
Exit Sub
End If
RecurseNetworkL evels(lngEnumHa ndle)
WNetCloseEnum(l ngEnumHandle)
End Sub
Private Sub RecurseNetworkL evels(ByVal lngEnumHandle As Integer)
Dim nrNetInfo() As NETRESOURCE
Dim i As Integer
Dim s As String
Dim stNetRes As NETRESOURCE
Dim cbBuff As Integer = 1023 * Len(stNetRes) ' 32kb
Dim lpBuff As Integer
Dim cCount As Integer = -1 ' Retrieve All
Dim p As Integer ' Pointer
Dim lngReturn As Integer
Do
lpBuff = GlobalAlloc(GPT R, cbBuff)
lngReturn = WNetEnumResourc e(lngEnumHandle , cCount, lpBuff, cbBuff)
If lngReturn = 234 Then ' 234 More data is available.
'ERROR_MORE_DAT A()
If lpBuff <> 0 Then GlobalFree(lpBu ff)
cbBuff = cbBuff * 2 ' 64kb, 128kb ...
End If
Loop While lngReturn = 234
If lngReturn = 0 Then
p = lpBuff
ReDim nrNetInfo(cCoun t - 1)
For i = 1 To cCount
Dim ptrUser As New IntPtr(p)
stNetRes = Marshal.PtrToSt ructure(ptrUser , GetType(NETRESO URCE))
nrNetInfo(i - 1) = stNetRes
p = p + Len(stNetRes)
Next
Else
Dim Buffer As String = Space(255)
FormatMessage(F ORMAT_MESSAGE_F ROM_SYSTEM, 0, lngReturn, _
LANG_NEUTRAL, Buffer, 255, 0)
Debug.WriteLine (Buffer.Trim)
If lpBuff <> 0 Then GlobalFree(lpBu ff)
Exit Sub
End If
'----------------------------------------------------------------
If cCount <= 0 Then Exit Sub
For i = 0 To cCount - 1
ProcessEntry(nr NetInfo(i))
If RESOURCEUSAGE_C ONTAINER = (nrNetInfo(i).d wUsage And _
RESOURCEUSAGE_C ONTAINER) Then
lngEnumHandle = GetNetworkHandl e(nrNetInfo(i))
If lngEnumHandle <> 0 Then
RecurseNetworkL evels(lngEnumHa ndle)
WNetCloseEnum(l ngEnumHandle)
End If
End If
Next
'---------------------------------------------------------------
If lpBuff <> 0 Then GlobalFree(lpBu ff)
End Sub
Private Sub ProcessEntry(By Ref nr As NETRESOURCE)
Dim strName, strComment As String
Dim ptrString As New IntPtr(nr.lpRem oteName)
strName = Marshal.PtrToSt ringAnsi(ptrStr ing)
ptrString = New IntPtr(nr.lpCom ment)
strComment = Marshal.PtrToSt ringAnsi(ptrStr ing)
Select Case nr.dwDisplayTyp e
Case RESOURCEDISPLAY TYPE_DOMAIN
m_strNetworkNam e = strName
Console.Write(" Network Name ")
Console.WriteLi ne(m_strNetwork Name)
Case RESOURCEDISPLAY TYPE_SERVER
Console.Write(" Server ")
Console.Write(s trName)
Console.Write(" ")
Console.WriteLi ne(strComment)
Case RESOURCEDISPLAY TYPE_SHARE
Console.Write(" Share ")
Console.Write(s trName)
Console.Write(" ")
Console.WriteLi ne(strComment)
End Select
End Sub
Private Function GetNetworkHandl e(ByRef nrInit As NETRESOURCE, _
Optional ByRef fInit As Boolean = False) As Integer
Dim lngReturn As Integer
Dim lngEnumHandle As Integer
If fInit Then
lngReturn = WNetOpenEnum(RE SOURCE_GLOBALNE T, RESOURCETYPE_DI SK, _
0, Nothing, lngEnumHandle)
Else
lngReturn = WNetOpenEnum(RE SOURCE_GLOBALNE T, RESOURCETYPE_DI SK, _
0, nrInit, lngEnumHandle)
End If
If lngReturn = 0 Then
Return lngEnumHandle
Else
Dim strName As String
Dim ptrString As New IntPtr(nrInit.l pRemoteName)
strName = Marshal.PtrToSt ringAnsi(ptrStr ing)
Console.WriteLi ne(strName & " - " & lngReturn)
Select Case lngReturn
Case 1208
Dim a As New String(" ", 255)
Dim b As New String(" ", 255)
Dim Buffer As New String(" ", 255)
Console.WriteLi ne("An extended error has occurred. ERROR_EXTENDED_ ERROR ")
WNetGetLastErro r(lngReturn, a, 255, b, 255)
Console.WriteLi ne(a.Trim)
If b.Trim.Length > 0 Then Debug.WriteLine (b.Trim)
Case Else
Dim Buffer As New String(" ", 255)
Buffer = Space(255)
FormatMessage(F ORMAT_MESSAGE_F ROM_SYSTEM, 0, lngReturn, LANG_NEUTRAL,
Buffer, 255, 0)
Console.WriteLi ne(Trim(Buffer) )
End Select
Return 0
End If
End Function
End Module
Ken
-----------------
"Thomas Müller" <sa******@hotma il.com> wrote in message
news:02******** *************** *****@phx.gbl.. .
Hi,
I need a way to find the names of the computers that are
reachable over a network. Ideally when it is executed it
should report back wich computernames are present.
I have seen one solution with System.Director yServices but
that doesn't work for me because the required isn't
installed on the computer.
Any way to do this preferbly with existing methods would be
apreciated.
Thanks,
Thomas