Windows Shell namespace organizes all objects (both storage and non-storage
specific) of a file system into a single hierarchical tree. There are
certain standard (virtual) folders that are automatically created and managed
by the operating system, users cannot create these virtual folders.
To get the physical path that these virtual folders are pointing to, the OS
provides SHGetSpecialFolderLocation and SHGetPathFromIDList functions.
To retrieve a folder's physical path, pass it's corressponding CSIDL value to
the fGetSpecialFolderLocation function.
Note: Not all system folders exist under both Win 9x and
NT/2000. Please read the comments preceding each constant declaration
for more details.
Public Const CSIDL_FLAG_CREATE = &H8000
Public Const CSIDL_ADMINTOOLS = &H30
Public Const CSIDL_ALTSTARTUP = &H1D
Public Const CSIDL_APPDATA = &H1A
Public Const CSIDL_BITBUCKET = &HA
Public Const CSIDL_COMMON_ADMINTOOLS = &H2F
Public Const CSIDL_COMMON_ALTSTARTUP = &H1E
Public Const CSIDL_COMMON_APPDATA = &H23
Public Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19
Public Const CSIDL_COMMON_DOCUMENTS = &H2E
Public Const CSIDL_COMMON_FAVORITES = &H1F
Public Const CSIDL_COMMON_PROGRAMS = &H17
Public Const CSIDL_COMMON_STARTMENU = &H16
Public Const CSIDL_COMMON_STARTUP = &H18
Public Const CSIDL_COMMON_TEMPLATES = &H2D
Public Const CSIDL_CONTROLS = &H3
Public Const CSIDL_COOKIES = &H21
.
Public Const CSIDL_DESKTOP = &H0
Public Const CSIDL_DESKTOPDIRECTORY = &H10
Public Const CSIDL_DRIVES = &H11
Public Const CSIDL_FAVORITES = &H6
Public Const CSIDL_FONTS = &H14
Public Const CSIDL_HISTORY = &H22
Public Const CSIDL_INTERNET = &H1
Public Const CSIDL_INTERNET_CACHE = &H20
Public Const CSIDL_LOCAL_APPDATA = &H1C
Public Const CSIDL_MYPICTURES = &H27
Public Const CSIDL_NETHOOD = &H13
Public Const CSIDL_NETWORK = &H12
Public Const CSIDL_PERSONAL = &H5
Public Const CSIDL_PRINTERS = &H4
Public Const CSIDL_PRINTHOOD = &H1B
Public Const CSIDL_PROFILE = &H28
Public Const CSIDL_PROGRAM_FILES = &H2A
Public Const CSIDL_PROGRAM_FILES_COMMON = &H2B
Public Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
Public Const CSIDL_PROGRAM_FILESX86 = &H2A
Public Const CSIDL_PROGRAMS = &H2
Public Const CSIDL_RECENT = &H8
Public Const CSIDL_SENDTO = &H9
Public Const CSIDL_STARTMENU = &HB
Public Const CSIDL_STARTUP = &H7
Public Const CSIDL_SYSTEM = &H25
Public Const CSIDL_SYSTEMX86 = &H29
Public Const CSIDL_TEMPLATES = &H15
Public Const CSIDL_WINDOWS = &H24
Public Const NOERROR = 0
Private Declare Function apiSHGetSpecialFolderLocation Lib "shell32" _
Alias "SHGetSpecialFolderLocation" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
ppidl As Long) _
As Long
Private Declare Function apiSHGetPathFromIDList Lib "shell32" _
Alias "SHGetPathFromIDList" _
(pidl As Long, _
ByVal pszPath As String) _
As Long
Private Declare Sub sapiCoTaskMemFree Lib "ole32" _
Alias "CoTaskMemFree" _
(ByVal pv As Long)
Private Const MAX_PATH = 260
Function fGetSpecialFolderLocation(ByVal lngCSIDL As Long) As String
Dim lngRet As Long
Dim strLocation As String
Dim pidl As Long
lngRet = apiSHGetSpecialFolderLocation(hWndAccessApp, lngCSIDL, pidl)
If lngRet = NOERROR Then
strLocation = Space$(MAX_PATH)
lngRet = apiSHGetPathFromIDList(ByVal pidl, strLocation)
If Not lngRet = 0 Then
fGetSpecialFolderLocation = Left$(strLocation, _
InStr(strLocation, vbNullChar) - 1)
End If
Call sapiCoTaskMemFree(pidl)
End If
End Function
|