How to get special folders
Posted on July 10, 2011
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 'System & API - How to get special folders 'Declarations to find special folders 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 Type SHITEMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As SHITEMID End Type Private Const MAX_PATH As Integer = 260 Public Function fGetSpecialFolder(ByVal CSIDL As Long) As String 'This function will find My documents path. 'value Result '2 C:\Documents and Settings\<USERNAME>\Start Menu\Programs '5 C:\Documents and Settings\<USERNAME>\My Documents '6 C:\Documents and Settings\<USERNAME>\Favorites '7 C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Startup '8 C:\Documents and Settings\<USERNAME>\Recent '9 C:\Documents and Settings\<USERNAME>\SendTo '11 C:\Documents and Settings\<USERNAME>\Start Menu '13 C:\Documents and Settings\scsrinivasan\My Documents\My Music '16 C:\Documents and Settings\<USERNAME>\Desktop '19 C:\Documents and Settings\<USERNAME>\NetHood '20 C:\WINNT\Fonts '21 C:\Documents and Settings\<USERNAME>\Templates '22 C:\Documents and Settings\All Users\Start Menu '23 C:\Documents and Settings\All Users\Start Menu\Programs '24 C:\Documents and Settings\All Users\Start Menu\Programs\Startup '25 C:\Documents and Settings\All Users\Desktop '26 C:\Documents and Settings\<USERNAME>\Application Data '27 C:\Documents and Settings\<USERNAME>\PrintHood '28 C:\Documents and Settings\<USERNAME>\Local Settings\Application Data '31 C:\Documents and Settings\All Users\Favorites '32 C:\Documents and Settings\<USERNAME>\Local Settings\Temporary Internet Files '33 C:\Documents and Settings\<USERNAME>\Cookies '34 C:\Documents and Settings\<USERNAME>\Local Settings\History '35 C:\Documents and Settings\All Users\Application Data '36 C:\WINNT37 C:\WINNT\system32 '38 C:\Program Files '39 C:\Data\My Pictures '40 C:\Documents and Settings\<USERNAME> '41 C:\WINNT\system32 '43 C:\Program Files\Common Files '45 C:\Documents and Settings\All Users\Templates '46 C:\Documents and Settings\All Users\Documents '47 C:\Documents and Settings\All Users\Start Menu\Programs\Administrative Tools '48 C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Administrative Tools Dim sPath As String Dim IDL As ITEMIDLIST On Error GoTo fGetSpecialFolder_Error fGetSpecialFolder = "" If SHGetSpecialFolderLocation(0, CSIDL, IDL) = 0 Then sPath = Space$(MAX_PATH) If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "" End If End If On Error GoTo 0 Exit Function fGetSpecialFolder_Error: RaiseEvent ErrRepo("fGetSpecialFolder", Err.Number, Err.Description, False) Err.Clear Resume Next End Function |