Her er noget kode, taget direkte fra
www.mvps.org/vbnet:'---- FORM CODE -----
Option Explicit
Private Sub Command1_Click()
Dim bi As BROWSEINFO
Dim pidl As Long
Dim path As String
Dim pos As Integer
Label1.Caption = ""
'Fill the BROWSEINFO structure with the
'needed data. To accomodate comments, the
'With/End With sytax has not been used, though
'it should be your 'final' version.
'hwnd of the window that receives messages
'from the call. Can be your application
'or the handle from GetDesktopWindow().
bi.hOwner = Me.hWnd
'Pointer to the item identifier list specifying
'the location of the "root" folder to browse from.
'If NULL, the desktop folder is used.
bi.pidlRoot = 0&
'message to be displayed in the Browse dialog
bi.lpszTitle = "Select your Windows\System\ directory"
'the type of folder to return.
bi.ulFlags = BIF_BROWSEFORPRINTER
'show the browse for folders dialog
pidl = SHBrowseForFolder(bi)
'the dialog has closed, so parse & display the
'user's returned folder selection contained in pidl
path = Space$(MAX_PATH)
If SHGetPathFromIDList(ByVal pidl, ByVal path) Then
pos = InStr(path, Chr$(0))
Label1.Caption = Left(path, pos - 1)
End If
Call CoTaskMemFree(pidl)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
'--end block--'
'------ MODULE CODE -----
Option Explicit
Public Type BROWSEINFO
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
Public Const BIF_RETURNONLYFSDIRS = &H1
Public Const BIF_DONTGOBELOWDOMAIN = &H2
Public Const BIF_STATUSTEXT = &H4
Public Const BIF_RETURNFSANCESTORS = &H8
Public Const BIF_BROWSEFORCOMPUTER = &H1000
Public Const BIF_BROWSEFORPRINTER = &H2000
Public Const MAX_PATH = 260
Public Declare Function SHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long
Public Declare Sub CoTaskMemFree Lib "ole32" _
(ByVal pv As Long)
'--end block--'
Har desværre ikke haft tid til at teste det, men har selv brugt dette, og det virker ganske udmærket... Hvis du har problemer med at forstå de forskellige ting, så sig endeligt til.