Option Explicit
Private Declare Function NetApiBufferFree Lib "Netapi32" _
(ByVal Buffer As Long) As Long
Private Declare Function NetServerEnum Lib "netapi32.dll" _
(ByVal ServerName As String, _
ByVal Level As Long, _
Buffer As Long, _
ByVal PrefMaxLen As Long, _
EntriesRead As Long, _
TotalEntries As Long, _
ByVal ServerType As Long, _
ByVal Domain As String, _
ResumeHandle As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" _
(hpvDest As Any, _
ByVal hpvSource As Long, _
ByVal cbCopy As Long)
Private Declare Function lstrcpyW Lib "kernel32" _
(ByVal lpszDest As String, _
ByVal lpszSrc As Long) As Long
Private Const ERROR_MORE_DATA As Long = 234&
Private Const ERROR_SUCCESS As Long = 0&
Private Enum ServerTypeEnum
SV_TYPE_WORKSTATION = &H1
End Enum
Const SIZE_SI_101 = 24
Private Type SERVER_INFO_101
dwPlatformId As Long
lpszServerName As Long
dwVersionMajor As Long
dwVersionMinor As Long
dwType As Long
lpszComment As Long
End Type
Private Sub Combo1_Change()
End Sub
Private Sub Command1_Click()
Dim i As Long
Dim NumberOfNames As Long
Dim SrvType As Long
Dim colServers As New Collection
NumberOfNames = EnumServers(colServers, SV_TYPE_WORKSTATION)
Combo1.Clear
If NumberOfNames > 0 Then
For i = 1 To NumberOfNames
Combo1.AddItem colServers(i)
Next
Combo1.ListIndex = 0
End If
End Sub
Private Function EnumServers(ServerCollection As Collection, _
ServerType As ServerTypeEnum) As Long
Dim strDomain As String
Dim lngLevel As Long
Dim i As Long
Dim lngBuffer As Long
Dim lngTBuffer As Long
Dim lngPfMaxLen As Long
Dim lngEntriesRead As Long
Dim lngTotalEntries As Long
Dim lngSrvType As Long
Dim lngResumeHandle As Long
Dim lngRet As Long
Dim SRVInfo As SERVER_INFO_101
lngLevel = 101
lngBuffer = 0
lngPfMaxLen = &HFFFFFFFF
lngEntriesRead = 0
lngTotalEntries = 0
lngResumeHandle = 0
lngSrvType = ServerType
Do
lngRet = NetServerEnum(vbNullString, lngLevel, lngBuffer, _
lngPfMaxLen, lngEntriesRead, lngTotalEntries, _
lngSrvType, strDomain, lngResumeHandle)
If lngEntriesRead > 0 Then
If ((lngRet = ERROR_SUCCESS) Or (lngRet = ERROR_MORE_DATA)) Then
lngTBuffer = lngBuffer
For i = 0 To lngEntriesRead - 1
RtlMoveMemory SRVInfo, lngTBuffer, SIZE_SI_101
ServerCollection.Add PointerToString(SRVInfo.lpszServerName)
lngTBuffer = lngTBuffer + SIZE_SI_101
Next i
Else
MsgBox "Fehler bei NetServerEnum: " & lngRet
End If
End If
NetApiBufferFree (lngBuffer)
Loop While lngEntriesRead < lngTotalEntries
EnumServers = lngTotalEntries
End Function
Private Function PointerToString(pString As Long) As String
Dim strStringA As String
Dim strStringB As String
Dim nRes As Long
strStringA = String(1000, "*")
nRes = lstrcpyW(strStringA, pString)
strStringB = StrConv(strStringA, vbFromUnicode)
PointerToString = Left(strStringB, InStr(strStringB, Chr$(0)) - 1)
End Function
Private Sub Form_Load()
End Sub