|
-
October 13th, 1999, 04:02 AM
#1
"Entire Network" list of servers
How do I get the list of server names that are displayed in "Entire Network" of the Windows Explorer?
Thanks in anticipation.
-
October 13th, 1999, 05:13 AM
#2
Re: "Entire Network" list of servers
wow! That was a tough one. I first thought that I just get the API declaration and spit out a few lines of vb code. And then... you know what happens...
here is, what I came up with.
option Explicit
private Declare Function lstrlenW Lib "kernel32" (byval lpString as Long) as Long
private Declare Function NetServerEnum Lib "netapi32" ( _
strServername as Any, _
byval level as Long, _
bufptr as Long, _
byval prefmaxlen as Long, _
entriesread as Long, _
totalentries 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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination as Any, Source as Any, byval Length as Long)
private Const SV_TYPE_SERVER as Long = &H2
private Type SV_100
platform as Long
name as Long
End Type
private Sub Command1_Click()
Dim l as Long
Dim entriesread as Long
Dim totalentries as Long
Dim hREsume as Long
Dim bufptr as Long
Dim level as Long
level = 100
Dim prefmaxlen as Long
prefmaxlen = 100
Dim lType as Long
lType = SV_TYPE_SERVER
Dim sv100 as SV_100
l = NetServerEnum(byval 0&, _
level, _
bufptr, _
prefmaxlen, _
entriesread, _
totalentries, _
lType, _
byval 0&, _
hREsume)
If l = 0 Or l = 234& then
Dim i as Long
for i = 0 to entriesread - 1
CopyMemory sv100, byval bufptr, len(sv100)
Debug.print Pointer2stringw(sv100.name)
bufptr = bufptr + len(sv100)
next i
End If
NetApiBufferFree bufptr
End Sub
private Function Pointer2stringw(byval l as Long) as string
Dim buffer() as Byte
Dim nLen as Long
nLen = lstrlenW(l) * 2
If nLen then
ReDim buffer(0 to (nLen - 1)) as Byte
CopyMemory buffer(0), byval l, nLen
Pointer2stringw = buffer
End If
End Function
This code prints all servers of the primary domain.
parts of the code taken from Karl Peterson's Web site (Pointer2Stringw).
-
October 13th, 1999, 06:12 AM
#3
Re: "Entire Network" list of servers
one more point.
It's "better" to set prefmaxlength to -1 (equivalent to MAX_PREFERRED_LENGTH) before calling NetServerEnum.
That way you can avoid the ERR_MORE_DATA (234) error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|