1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| Option Explicit
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_DOMAIN_ENUM As Long = &H80000000
Private Type SERVER_INFO_101
sv101_platform_id As Long
sv101_name As Long
sv101_version_major As Long
sv101_version_minor As Long
sv101_type As Long
sv101_comment As Long
End Type
Private Declare Function NetServerEnum Lib "netapi32" _
(ByVal servername As Long, _
ByVal level As Long, _
buf As Any, _
ByVal prefmaxlen As Long, _
entriesread As Long, _
totalentries As Long, _
ByVal servertype As Long, _
ByVal domain As Long, _
resume_handle As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pTo As Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Sub Form_Load()
Call GetServers
End Sub
Private Function GetServers() As Long
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim dwServertype As Long
Dim se101 As SERVER_INFO_101
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long
nStructSize = LenB(se101)
dwServertype = SV_TYPE_DOMAIN_ENUM
success = NetServerEnum(0&, 101, bufptr, MAX_PREFERRED_LENGTH, dwEntriesread, _
dwTotalentries, dwServertype, 0&, dwResumehandle)
If success = NERR_SUCCESS And success <> ERROR_MORE_DATA Then
For cnt = 0 To dwEntriesread - 1
CopyMemory se101, ByVal bufptr + (nStructSize * cnt), nStructSize
MsgBox GetPointerToByteStringW(se101.sv101_name)
Next
End If
Call NetApiBufferFree(bufptr)
GetServers = dwEntriesread
End Function
Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function |
Partager