试试如下代码: Option Explicit Type SHITEMID
cb As Long
abID() As Byte
End Type
Type ITEMIDLIST
mkid As SHITEMID
End Type Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pIdl As Long, ByVal pszPath As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
pIdl As ITEMIDLIST) As Long Private Const NOERROR = 0
Private Sub test() Dim wIdx As Integer, nFolder As Long
Dim sPath As String * 260
Dim IDL As ITEMIDLIST
Dim labFolderPath As String
If SHGetSpecialFolderLocation(0, nFolder, IDL) = NOERROR Then
If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then
labFolderPath = Left$(sPath, InStr(sPath, vbNullChar) - 1)
MsgBox "桌面路径:" & labFolderPath
End If
End If
End Sub
|