Citation :
' déclaration Api
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
'
Type SHITEMID
cb As Long
abID As Byte
End Type
Type ITEMIDLIST
mkid As SHITEMID
End Type
' constantes
Global Const NOERROR = 0
Global Const PATH_START = 7
Public Function CheminDemarrage() As String
Dim RetVal As Long
Dim Path As String ' déclaration des variables nécessaires
Dim IDL As ITEMIDLIST
RetVal = SHGetSpecialFolderLocation(0, PATH_START, IDL) ' appel de la fonction api
If RetVal = NOERROR Then
Path = Space(512) ' taille du tampon
RetVal = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path)
CheminDemarrage = Left(Path, InStr(Path, Chr(0)) - 1) ' extraction du chemin
Else
CheminDemarrage = ""
End If
End Function
|