Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List available servers

Status
Not open for further replies.

pokermat

Programmer
Jan 17, 2002
44
GB
This should be an easy one...

Does anyone know how to list available servers in VB?
 
Given the Domain name this code lists the servers. I can't remember were I found it thought...

-----------------------------------------------------------
Private Type SERVER_INFO_101
dw_platform_id As Long
ptr_name As Long
dw_ver_major As Long
dw_ver_minor As Long
dw_type As Long
ptr_comment As Long
End Type

Const SV_TYPE_DOMAIN_ENUM = &H80000000
Const SV_TYPE_ALL = &HFFFFFFFF

Private Const ERROR_MORE_DATA As Long = 234&

Private Declare Sub lstrcpyW Lib "kernel32" (vDest As Any, ByVal sSrc As Any)
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal pBuffer As Long) As Long
Private Declare Function NetServerEnum Lib "Netapi32.dll" (vServername As Any, ByVal lLevel As Long, vBufptr As Any, lPrefmaxlen As Long, _
lEntriesRead As Long, lTotalEntries As Long, vServerType As Any, ByVal sDomain As String, vResumeHandle As Any) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)

Private Sub AddDomainServers(lType As Long, Parentkey As String)

Dim lReturn As Long
Dim Server_Info As Long
Dim lEntries As Long
Dim lTotal As Long
Dim lMax As Long
Dim vResume As Variant
Dim tServer_info_101 As SERVER_INFO_101
Dim sServer As String
Dim sDomain As String
Dim lServerInfo101StructPtr As Long
Dim X As Long, i As Long
Dim bBuffer(512) As Byte
sDomain = StrConv(Parentkey, vbUnicode)


lReturn = NetServerEnum( _
ByVal 0&, _
101, _
Server_Info, _
lMax, _
lEntries, _
lTotal, _
ByVal lType, _
sDomain, _
vResume)

If lReturn <> 0 Then
'StatusBar1.Panels(&quot;msg&quot;).Text = &quot;Systemmessages here&quot;
Exit Sub
End If

X = 1
lServerInfo101StructPtr = Server_Info

Do While X <= lTotal
DoEvents
CopyMem tServer_info_101, _
ByVal lServerInfo101StructPtr, _
Len(tServer_info_101)

lstrcpyW bBuffer(0), _
tServer_info_101.ptr_name


i = 0
Do While bBuffer(i) <> 0
sServer = sServer & _
Chr$(bBuffer(i))
i = i + 2
DoEvents
Loop
MsgBox sServer 'do your coding here!
X = X + 1
sServer = &quot;&quot;
lServerInfo101StructPtr = _
lServerInfo101StructPtr + _
Len(tServer_info_101)
Loop
lReturn = NetApiBufferFree(Server_Info)
End Sub
------------------------------------------------------------

Use as:
AddDomainServers SV_TYPE_ALL, &quot;MyDomainName&quot; Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top