3 façons de récupérer l'adresse d'un dossier spécial de windows

Résolu
cs_candyraton Messages postés 109 Date d'inscription dimanche 27 juillet 2008 Statut Membre Dernière intervention 2 février 2012 - 16 août 2008 à 16:14
cs_candyraton Messages postés 109 Date d'inscription dimanche 27 juillet 2008 Statut Membre Dernière intervention 2 février 2012 - 24 août 2008 à 18:03
Bonjour,

J'ai relever 3 façon de faire;
Y en a t'il une mieux que l'autre?
Marche t'elles toutes sur tout les windows?

1):  cible = Programs & "" & filename
'AllUsersDesktop
'AllUsersStartMenu
'AllUsersPrograms
'AllUsersStartup
'DesktopPath
'Favorites
'Fonts
'MyDocuments
'NetHood
'PrintHood
'Programs
'Récent
'SendTo
'StartMenu
'Startup
'Templates

2)  cible = "%SystemRoot%\system32\NOTEPAD.EXE"
%windir%
...??

3)      cible = GetSpecialfolder(CSIDL_DESKTOP)
Private Function GetSpecialfolder(CSIDL As Long) As String
    Dim r As Long
    Dim IDL As ITEMIDLIST
    'Get the special folder
    r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    If r = NOERROR Then
        'Create a buffer
        Path$ = Space$(512)
        'Get the path from the IDList
        r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
        'Remove the unnecessary chr$(0)'s
        GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
        Exit Function
    End If
    GetSpecialfolder = ""
End Function
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3 '?!
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5 'mesdocs
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15

Merci

3 réponses

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
16 août 2008 à 16:51
Salut,

La plus sûre reste la troisième selon moi : elle utilise la dll standard de windows shell32 qui est la plus à même de savoir où trouver les dossiers spéciaux de windows selon la version de ce dernier !
______________________________________
DarK Sidious
3
cs_candyraton Messages postés 109 Date d'inscription dimanche 27 juillet 2008 Statut Membre Dernière intervention 2 février 2012 3
16 août 2008 à 22:18
Merci bien
0
cs_candyraton Messages postés 109 Date d'inscription dimanche 27 juillet 2008 Statut Membre Dernière intervention 2 février 2012 3
24 août 2008 à 18:03
Je me suis aperçu d'1 oubli alors voilà.

Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
Const MAX_PATH = 260
Private Type SHITEMID
    cb As Long
    abID As Byte
End Type
Private Type ITEMIDLIST
    mkid As SHITEMID
End Type
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    'Show an about window
    ShellAbout Me.hWnd, App.Title, "Created by the KPD-Team 1999", ByVal 0&
    'Set the graphical mode to persistent
    Me.AutoRedraw = True
    'Print the folders to the form
    Me.Print "Start menu folder: " + GetSpecialfolder(CSIDL_STARTMENU)
    Me.Print "Favorites folder: " + GetSpecialfolder(CSIDL_FAVORITES)
    Me.Print "Programs folder: " + GetSpecialfolder(CSIDL_PROGRAMS)
    Me.Print "Desktop folder: " + GetSpecialfolder(CSIDL_DESKTOP)
End Sub
Private Function GetSpecialfolder(CSIDL As Long) As String
    Dim r As Long
    Dim IDL As ITEMIDLIST
    'Get the special folder
    r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    If r = NOERROR Then
        'Create a buffer
        Path$ = Space$(512)
        'Get the path from the IDList
        r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
        'Remove the unnecessary chr$(0)'s
        GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
        Exit Function
    End If
    GetSpecialfolder = ""
End Function
0
Rejoignez-nous