I had asked a similar question a while back. One of the Guru
's answered me with this:
In a module:
Code:
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Type BROWSEINFO
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BROWSEINFO) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Const FLDR_NETWORK = &H12
Private Const BIF_BROWSEFORCOMPUTER = 4096
Public Function BrowseNetwork(ByVal lHwnd As Long, ByVal sTitle As String) As String
Dim tIDL As ITEMIDLIST
Dim lIDList As Long
Dim sBuffer As String
Dim tBI As BROWSEINFO
Dim sComputer As String
Dim lFolder As Long
lret = SHGetSpecialFolderLocation(0, FLDR_NETWORK, tIDL)
sComputer = Space(260)
With tBI
.hwndOwner = lHwnd
.pIDLRoot = tIDL.mkid.cb
.lpszTitle = lstrcat(sTitle, "")
.ulFlags = BIF_BROWSEFORCOMPUTER
.pszDisplayName = StrPtr(sComputer)
End With
lIDList = SHBrowseForFolder(tBI)
sComputer = StrConv(sComputer, vbUnicode)
BrowseNetwork = Left(sComputer, InStr(sComputer, Chr(0)) - 1)
Call CoTaskMemFree(lIDList)
End Function
Private Sub Command1_Click()
Caption = BrowseNetwork(hWnd, "Select a Computer..")
End Sub