Search Tools Links Login

Network Browser - Updated


Visual Basic 6, or VB Classic

I needed a way to select a network share, As I couldn't find any source I had to put this together. So now I am sharing it for others,
enjoy

Original Author: Malcolm Clarke

Assumptions

Nothing, it couldn't be simpler

Returns

String of the chosen path

API Declarations

Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_PATH As Long = 260
Private Const CSIDL_NETWORK As Long = &H12
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Type BROWSEINFO 'BI
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetSpecialFolderLocation _
Lib "shell32.dll" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long

Code

Public Function GetBrowseNetworkShare(ByVal hw As Variant) As String
  'returns only a valid share on a network server or workstation
  ' hw is a forms hWnd
  ' call: Text1.Text = GetBrowseNetworkShare(Me.hWnd)
  
  Dim BI As BROWSEINFO
  Dim pidl As Long
  Dim sPath As String
  Dim pos As Integer

  If SHGetSpecialFolderLocation(0, CSIDL_NETWORK, pidl) = ERROR_SUCCESS Then

    With BI
      .hOwner = hw
      .pidlRoot = pidl
      .pszDisplayName = Space$(MAX_PATH)
      .lpszTitle = "Select a network computer or share."
      .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    'show the browse dialog
    pidl = SHBrowseForFolder(BI)

    If pidl <> 0 Then
      
      sPath = Space$(MAX_PATH)

      If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
        pos = InStr(sPath, Chr$(0))
        GetBrowseNetworkShare = Left$(sPath, pos - 1)
      End If
    Else:
      GetBrowseNetworkShare = "\" & BI.pszDisplayName
    End If 'If pidl
  End If 'If SHGetSpecialFolderLocation
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 97 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.