Re: Как в VB получить список компов сети?
От: ma3ai  
Дата: 31.07.02 14:40
Оценка: 6 (2)
[VB & VBA]
Может и Вам пригодиться. Работает в локальной сети. Надеюсь разберётесь что к чему

Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function NetServerEnum Lib "netapi32" (Servername As Any, ByVal Level As Long, Address As Long, ByVal prefmaxlen As Long, ServersCount As Long, Count As Long, ByVal ServerType As Long, strDomain As Any, resumehandle As Long) As Long
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long


Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4

Private Type SV_100
  platform As Long
  name As Long
End Type

Public Function GetServers(Domain As String) As String
'
    Dim Response As Long
    Dim ServersCount As Long
    Dim Count As Long
    Dim hResume As Long
    Dim Address As Long
    Dim Level As Long
    Dim prefmaxlen As Long
    Dim ServerType As Long
    Dim Buffer() As Byte
    Dim Iterator As Long
    Dim sv100 As SV_100

    Level = 100
    prefmaxlen = -1

    ServerType = SV_TYPE_SERVER
    
    Buffer = Domain & vbNullChar
    Response = NetServerEnum(ByVal 0&, Level, Address, prefmaxlen, ServersCount, Count, ServerType, Buffer(0), hResume)
    
    If Response = 0 Or Response = 234& Then
        For Iterator = 0 To ServersCount - 1
            CopyMemory sv100, ByVal Address, Len(sv100)
            GetServers = GetServers & vbLf & Pointer2StringW(sv100.name)
            Address = Address + Len(sv100)
        Next
    Else
        GetServers = "#Error"
    End If
    NetApiBufferFree Address
End Function

Private Function Pointer2StringW(ByVal Address As Long) As String
    Dim Buffer() As Byte
    Dim Count As Long
    
    Count = lstrlenW(Address) * 2
    If Count Then
        ReDim Buffer(0 To (Count - 1)) As Byte
        CopyMemory Buffer(0), ByVal Address, Count
        Pointer2StringW = Buffer
    End If
End Function

...
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.