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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a DirListBox show "Entire Network"

Status
Not open for further replies.

hankins1984

IS-IT--Management
Mar 11, 2002
198
GB
Hi i would like to know if there is a way of making a DirListBox show the "Entire Network" list at start-up so that you can see all the computers on domain/workgroup.

Thanx in advance Matthew Hankins

Network Technicain @ DGI Hereford
 
Please someone has to know this one Matthew Hankins

Network Technicain @ DGI Hereford
 
anyone pls help Matthew Hankins

Network Technicain @ DGI Hereford
 
I know how to make it start in the c drive, that is easy dir1.path = ("c:")

but i would like to know how you make it start in the Entire Network area Matthew Hankins

Network Technicain @ DGI Hereford
 
Since you're dealing with network services, and not mapped drived, I do not belive that you can get the DirListBox to work. Below is some recursive code that uses of number of API to get network resources, and populates and regular list box with this information.

'===========================================================

Option Explicit

'===========================================================
' Network Services

Public Declare Function WNetOpenEnum _
Lib "mpr.dll" Alias "WNetOpenEnumA" _
(ByVal dwScope As Long, ByVal dwType As Long, _
ByVal dwUsage As Long, lpNetResource As Any, lppEnumHwnd As Long) _
As Long
'-----------------------------------------------------------
Public Declare Function WNetEnumResource _
Lib "mpr.dll" Alias "WNetEnumResourceA" _
(ByVal pEnumHwnd As Long, lpcCount As Long, _
lpBuffer As NETRESOURCE, lpBufferSize As Long) _
As Long
'-----------------------------------------------------------
Public Declare Function WNetCloseEnum _
Lib "mpr.dll" _
(ByVal lLng_EnumHand As Long) _
As Long
'-----------------------------------------------------------
Public Declare Function StrLenA _
Lib "kernel32" Alias "lstrlenA" _
(ByVal Ptr As Long) _
As Long
'-----------------------------------------------------------
Public Declare Function StrCopyA _
Lib "kernel32" Alias "lstrcpyA" _
(ByVal RetVal As String, ByVal Ptr As Long) _
As Long
'-----------------------------------------------------------
Public Type NETRESOURCE
tLng_Scope As Long
tLng_Type As Long
tLng_DisplayType As Long
tLng_Usage As Long
tLng_LocalName As Long
tLng_RemoteName As Long
tLng_Comment As Long
tLng_Provider As Long
End Type
'-----------------------------------------------------------
Const MAX_RESOURCES As Long = 256
Const NOT_A_CONTAINER As Long = -1
Const RESOURCE_GLOBALNET As Long = &H2&
Const RESOURCETYPE_ANY As Long = &H0&
Const RESOURCEUSAGE_ALL As Long = &H0&
Const SUCCESS As Long = 0&
Const RESOURCE_ENUM_ALL As Long = &HFFFF
'===========================================================

Private Sub cmdGetNetwork_Click()

ShowResources

End Sub

'===========================================================

Private Sub ShowResources()

Dim lLng_RetVal As Long
Dim lLng_EnumHand As Long
Dim lLng_Count As Long
Dim lInt_Idx As Long
Dim lLng_BuffSize As Long
Dim lNet_Resource(MAX_RESOURCES) As NETRESOURCE

lLng_EnumHand = 0&
lLng_RetVal = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, ByVal 0&, lLng_EnumHand)

If (lLng_RetVal = SUCCESS) Then
lLng_Count = RESOURCE_ENUM_ALL
lLng_BuffSize = UBound(lNet_Resource) * Len(lNet_Resource(0))
lLng_RetVal = WNetEnumResource(lLng_EnumHand, lLng_Count, lNet_Resource(0), lLng_BuffSize)
If (lLng_Count > 0) Then
For lInt_Idx = 0 To lLng_Count - 1
lstResources.AddItem (PointerToAsciiStr(lNet_Resource(lInt_Idx).tLng_RemoteName))
DoEvents
ShowResourcesThisItem lNet_Resource(lInt_Idx), ""
Next lInt_Idx
End If
End If

If (lLng_EnumHand <> 0) Then
Call WNetCloseEnum(lLng_EnumHand)
End If

End Sub

'-----------------------------------------------------------

Private Sub ShowResourcesThisItem(rNet_Resource As NETRESOURCE, rStr_Spacer As String)

Dim lLng_RetVal As Long
Dim lLng_EnumHand As Long
Dim lLng_Count As Long
Dim lInt_Idx As Long
Dim lLng_BuffSize As Long
Dim lNet_Resource(MAX_RESOURCES) As NETRESOURCE

lLng_RetVal = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL, rNet_Resource, lLng_EnumHand)

If (lLng_RetVal = SUCCESS) Then
lLng_Count = RESOURCE_ENUM_ALL
lLng_BuffSize = UBound(lNet_Resource) * Len(lNet_Resource(0))
lLng_RetVal = WNetEnumResource(lLng_EnumHand, lLng_Count, lNet_Resource(0), lLng_BuffSize)
If (lLng_Count > 0) Then
For lInt_Idx = 0 To lLng_Count - 1
lstResources.AddItem rStr_Spacer & (PointerToAsciiStr(lNet_Resource(lInt_Idx).tLng_RemoteName))
DoEvents
ShowResourcesThisItem lNet_Resource(lInt_Idx), (rStr_Spacer & Space(3))
Next lInt_Idx
End If
End If

If (lLng_EnumHand <> 0) Then
Call WNetCloseEnum(lLng_EnumHand)
End If

End Sub

'-----------------------------------------------------------

Public Function PointerToAsciiStr(ByVal vLng_StringPtr As Long) As String

Dim lLng_StrLen As Long
Dim lStr_StrValue As String
Dim lLng_NullPos As Long
Dim lLng_RetVal As Long
Dim lStr_ReturnString As String

lLng_StrLen = StrLenA(vLng_StringPtr)
If vLng_StringPtr > 0 And lLng_StrLen > 0 Then
lStr_StrValue = Space$(lLng_StrLen + 1)
lLng_RetVal = StrCopyA(lStr_StrValue, vLng_StringPtr)
lLng_NullPos = InStr(lStr_StrValue, Chr$(0))
If (lLng_NullPos > 0) Then
lStr_ReturnString = Left(lStr_StrValue, (lLng_NullPos - 1))
Else
lStr_ReturnString = lStr_StrValue
End If
Else
lStr_ReturnString = vbNullString
End If

PointerToAsciiStr = lStr_ReturnString

End Function

'=========================================================== Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Sorry i am new to VB, what do you mean when you say &quot; API &quot; Matthew Hankins

Network Technicain @ DGI Hereford
 
Can anyone tell me what an API Is Matthew Hankins

Network Technicain @ DGI Hereford
 
Perhaps you would like to look at a control on where you will find ExplorerTreeView ocx.

Network technician are you. I would have thought you knew what the Windows API is. As am example

Public Declare Function StrCopyA Lib &quot;kernel32&quot; Alias &quot;lstrcpyA&quot; (ByVal RetVal As String, ByVal Ptr As Long) As Long

Here StrCopyA is part of kernel32.dll, a windows component. Peter Meachem
peter @ accuflight.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top