Attribute VB_Name = "modPaths" Option Explicit '============================================================================================================= ' ' modPaths Module ' --------------- ' ' Created By : Kevin Wilson ' http://www.TheVBZone.com ( The VB Zone ) ' http://www.TheVBZone.net ( The VB Zone .net ) ' ' Last Update : April 15, 2000 ' ' VB Versions : 5.0 / 6.0 ' ' Requires : Internet Explorer 4.x or better (see documentation below) ' ' Description : This module is designed to easily return the locations of key special directories on the ' user's computer. ' ' NOTE : Some directories can only be returned on Windows NT, or if Internet Explorer 4.x or better ' is installed on the user's computer. See documentation below for more details. ' ' NOTE : Most of these settings can be retrieved directly from the Windos registry by accessing ' stored paths under the following keys : ' ' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion ' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders ' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders ' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders ' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders ' HKEY_USERS\.Default\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders ' HKEY_USERS\.Default\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders ' ' Example Use : ' ' MsgBox "Windows Desktop Path = " & GetSpecialfolder(CSIDL_DESKTOP) ' '============================================================================================================= ' ' LEGAL: ' ' You are free to use this code as long as you keep the above heading information intact and unchanged. Credit ' given where credit is due. Also, it is not required, but it would be appreciated if you would mention ' somewhere in your compiled program that that your program makes use of code written and distributed by ' Kevin Wilson (www.TheVBZone.com). Feel free to link to this code via your web site or articles. ' ' You may NOT take this code and pass it off as your own. You may NOT distribute this code on your own server ' or web site. You may NOT take code created by Kevin Wilson (www.TheVBZone.com) and use it to create products, ' utilities, or applications that directly compete with products, utilities, and applications created by Kevin ' Wilson, TheVBZone.com, or Wilson Media. You may NOT take this code and sell it for profit without first ' obtaining the written consent of the author Kevin Wilson. ' ' These conditions are subject to change at the discretion of the owner Kevin Wilson at any time without ' warning or notice. Copyright© by Kevin Wilson. All rights reserved. ' '============================================================================================================= Public Type SHITEMID cb As Long abID As Byte End Type Public Type ITEMIDLIST mkID As SHITEMID End Type Public Enum SystemFolders ' Standard Windows 95 SDK Documented Folder Flags ' 1 = Hidden Folder ' 2 = Internet Explorer required ' 3 = Virtual Folder ' 4 = Windows NT and Windows 9x ' 5 = Windows NT Only ' 6 = Windows 2000 Only ' 7 = Alpha Systems Only CSIDL_BITBUCKET = 10 ' 1 / Recycle Bin CSIDL_CONTROLS = 3 ' 3 / Control Panel CSIDL_DESKTOP = 0 ' 4 / Windows Desktop CSIDL_DESKTOPDIRECTORY = 16 ' 5 / Directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). CSIDL_DRIVES = 17 ' 3 / My Computer CSIDL_FONTS = 20 ' 3 / Virtual folder containing fonts. CSIDL_NETHOOD = 19 ' 5 / Directory containing objects that appear in the network neighborhood. CSIDL_NETWORK = 18 ' 3 / Network Neighborhood CSIDL_PERSONAL = 5 ' 4 / Directory that serves as a common respository for documents. CSIDL_PRINTERS = 4 ' 3 / Printers folder CSIDL_PROGRAMS = 2 ' 5 / Directory that contains the user’s program groups CSIDL_RECENT = 8 ' 4 / Directory that contains the user’s most recently used documents. CSIDL_SENDTO = 9 ' 4 / Directory that contains Send To menu items. CSIDL_STARTMENU = 11 ' 5 / Directory containing Start menu items. CSIDL_STARTUP = 7 ' 5 / Directory that corresponds to the user’s Startup program group. CSIDL_TEMPLATES = 21 ' 4 / Directory that serves as a common repository for document templates. ' Folder Flags Not Documented In The Windows 95 SDK (Found info on Microsoft's web site) CSIDL_ALTSTARTUP = 29 ' 2 / User's Startup Group CSIDL_APPDATA = 26 ' 5 / Application data directory for the current user CSIDL_COMMON_ALTSTARTUP = 30 ' 2 / Common Startup Group CSIDL_COMMON_DESKTOPDIRECTORY = 25 ' 4 / Desktop Directory - Common CSIDL_COMMON_FAVORITES = 31 ' 5 / Directory that serves as a common repository for all users' favorite items CSIDL_COMMON_PROGRAMS = 23 ' 4 / Program Menu - All Users CSIDL_COMMON_STARTMENU = 22 ' 4 / Start Menu - Common CSIDL_COMMON_STARTUP = 24 ' 4 / Start Up Folder - Common CSIDL_COOKIES = 33 ' 2 / Cookies directory for the current user CSIDL_FAVORITES = 6 ' 4 / Windows Favorites directory CSIDL_HISTORY = 34 ' 2 / History directory for the current user CSIDL_INTERNET = 1 ' 2 / Virtual folder representing the Internet. CSIDL_INTERNET_CACHE = 32 ' 2 / Internet Explorer cache directory for the current user CSIDL_PRINTHOOD = 27 ' 5 / Directory containing objects that appear in the Printer neighborhood. ' Folder flags that are only applicable for Windows 2000, or on RISC systems. CSIDL_ADMINTOOLS = &H30 ' 6 / Directory that is used to store administrative tools for an individual user CSIDL_COMMON_ADMINTOOLS = &H2F ' 6 / Directory containing containing administrative tools for all users of the computer. CSIDL_MYPICTURES = &H27 ' 6 / My Pictures folder CSIDL_PROGRAM_FILES = &H26 ' 6 / Program Files folder. A typical path is C:\Program Files. CSIDL_PROGRAM_FILES_COMMONX86 = &H2C ' 7 / Program Files folder for x86 apps on Alpha systems (RISC systems) CSIDL_PROGRAM_FILES_COMMON = &H2B ' 6 / A folder for components that are shared across applications. A typical path is C:\Program Files\Common. CSIDL_SYSTEM = &H25 ' 6 / System folder. A typical path is C:\WINNT\SYSTEM32. CSIDL_SYSTEMX86 = &H29 ' 7 / System folder for x86 applications on Alpha systems (RISC systems) CSIDL_WINDOWS = &H24 ' 6 / Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. End Enum Public Const MAX_PATH = 260 Public Const NOERROR = 0 Public Declare Function SHGetSpecialFolderLocation Lib "SHELL32.DLL" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long Public Declare Function SHGetPathFromIDList Lib "SHELL32.DLL" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long ' Function that returns the path to the specified directory Public Function GetSpecialfolder(FolderToReturn As SystemFolders) As String On Error Resume Next Dim ReturnCode As Long Dim ReturnPath As String Dim ID_List As ITEMIDLIST ' Get the special folder ReturnCode = SHGetSpecialFolderLocation(0, FolderToReturn, ID_List) If ReturnCode = NOERROR Then ReturnPath = Space(512) ' Create a buffer ReturnCode = SHGetPathFromIDList(ByVal ID_List.mkID.cb, ByVal ReturnPath) ' Get the path from the IDList GetSpecialfolder = Left(ReturnPath, InStr(ReturnPath, Chr(0)) - 1) ' Remove the unnecesarry chr(0)'s Exit Function End If GetSpecialfolder = "" End Function '________________________________________________________________________________ 'CSIDL Values : '============== ' 'There are a number of folders that are used frequently by applications, but may 'not have the same name or location on any given system. For example, the system 'folder may be "C:\Windows" on one system and "C:\Winnt" on another. CSIDL values 'provide a unique system-independent way to identify these special folders. They 'supersede the use of environment variables for this purpose. ' 'A CSIDL is used in conjunction with one of four shell functions, 'SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation, and 'SHGetSpecialFolderPath, to retrieve a special folder's pathname or item ID list '(PIDL). ' 'If a special folder does not exist, you can force it to be created by using the 'following special CSIDL: ' 'CSIDL_FLAG_CREATE ' [Version 5.0] Combine this CSIDL with any of the CSIDLs listed below to ' force the creation of the associated folder. ' 'The remaining CSIDLs correspond to either file system or virtual folders. Where 'the CSIDL identifies a file system folder, a commonly used path is given as an 'example. Other paths may be used. Some CSIDLs can be mapped to an equivalent '%VariableName% environment variable. CSIDLs are much more reliable, however, 'and should be used if at all possible. ' '-------------------------------------------------------------------------------- ' 'CSIDL_ADMINTOOLS ' [Version 5.0] File system directory that is used to store administrative ' tools for an individual user. The Microsoft Management Console will save ' customized consoles to this directory and it will roam with the user. ' 'CSIDL_ALTSTARTUP ' File system directory that corresponds to the user's nonlocalized ' Startup program group. ' 'CSIDL_APPDATA ' [Version 4.71] File system directory that serves as a common repository ' for application-specific data. A typical path is C:\Documents and ' Settings\username\Application Data. This CSIDL is supported by the ' redistributable ShFolder.dll for systems that do not have the Internet ' Explorer 4.0 integrated shell installed. ' 'CSIDL_BITBUCKET ' Virtual folder containing the objects in the user's Recycle Bin. ' 'CSIDL_COMMON_ADMINTOOLS ' [Version 5.0] File system directory containing containing administrative ' tools for all users of the computer. ' 'CSIDL_COMMON_ALTSTARTUP ' File system directory that corresponds to the nonlocalized Startup ' program group for all users. Valid only for Windows NT® systems. ' 'CSIDL_COMMON_APPDATA ' [Version 5.0] Application data for all users. A typical path is ' C:\Documents and Settings\All Users\Application Data. ' 'CSIDL_COMMON_DESKTOPDIRECTORY ' File system directory that contains files and folders that appear on the ' desktop for all users. A typical path is C:\Documents and ' Settings\All Users\Desktop. Valid only for Windows NT® systems. ' 'CSIDL_COMMON_DOCUMENTS ' File system directory that contains documents that are common to all users. ' A typical path is C:\Documents and Settings\All Users\Documents. Valid for ' Windows NT® systems and Windows 95 and Windows 98 systems with Shfolder.dll ' installed. ' 'CSIDL_COMMON_FAVORITES ' File system directory that serves as a common repository for all users' ' favorite items. Valid only for Windows NT® systems. ' 'CSIDL_COMMON_PROGRAMS ' File system directory that contains the directories for the common program ' groups that appear on the Start menu for all users. A typical path is ' C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for ' Windows NT® systems. ' 'CSIDL_COMMON_STARTMENU ' File system directory that contains the programs and folders that appear ' on the Start menu for all users. A typical path is C:\Documents and ' Settings\All Users\Start Menu. Valid only for Windows NT® systems. ' 'CSIDL_COMMON_STARTUP ' File system directory that contains the programs that appear in the ' Startup folder for all users. A typical path is C:\Documents and ' Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT® ' systems. ' 'CSIDL_COMMON_TEMPLATES ' File system directory that contains the templates that are available to ' all users. A typical path is C:\Documents and Settings\All Users\Templates. ' Valid only for Windows NT® systems. ' 'CSIDL_CONTROLS ' Virtual folder containing icons for the Control Panel applications. ' 'CSIDL_COOKIES ' File system directory that serves as a common repository for Internet ' cookies. A typical path is C:\Documents and Settings\username\Cookies. ' 'CSIDL_DESKTOP ' Windows Desktop—virtual folder that is the root of the namespace. ' 'CSIDL_DESKTOPDIRECTORY ' File system directory used to physically store file objects on the desktop ' (not to be confused with the desktop folder itself). A typical path is ' C:\Documents and Settings\username\Desktop ' 'CSIDL_DRIVES ' My Computer—virtual folder containing everything on the local ' computer: storage devices, printers, and Control Panel. The folder may ' also contain mapped network drives. ' 'CSIDL_FAVORITES ' File system directory that serves as a common repository for the user's ' favorite items. A typical path is C:\Documents and ' Settings\username\Favorites. ' 'CSIDL_FONTS ' Virtual folder containing fonts. A typical path is C:\WINNT\Fonts. ' 'CSIDL_HISTORY ' File system directory that serves as a common repository for Internet ' history items. ' 'CSIDL_INTERNET ' Virtual folder representing the Internet. ' 'CSIDL_INTERNET_CACHE ' File system directory that serves as a common repository for temporary ' Internet files. A typical path is C:\Documents and ' Settings\username\Temporary Internet Files. ' 'CSIDL_LOCAL_APPDATA ' [Version 5.0] File system directory that serves as a data repository for ' local (non-roaming) applications. A typical path is C:\Documents and ' Settings\username\Local Settings\Application Data. ' 'CSIDL_MYPICTURES ' [Version 5.0] My Pictures folder. A typical path is C:\Documents and ' Settings\username\My Documents\My Pictures. ' 'CSIDL_NETHOOD ' A file system folder containing the link objects that may exist in the ' My Network Places virtual folder. It is not the same as CSIDL_NETWORK, ' which represents the network namespace root. A typical path is ' C:\Documents and Settings\username\NetHood. ' 'CSIDL_NETWORK ' Network Neighborhood—virtual folder representing the root of the ' network namespace hierarchy. ' 'CSIDL_PERSONAL ' File system directory that serves as a common repository for documents. ' A typical path is C:\Documents and Settings\username\My Documents. ' 'CSIDL_PRINTERS ' Virtual folder containing installed printers. ' 'CSIDL_PRINTHOOD ' File system directory that contains the link objects that may exist in ' the Printers virtual folder. A typical path is C:\Documents and ' Settings\username\PrintHood. ' 'CSIDL_PROFILE ' [Version 5.0] User's profile folder. ' 'CSIDL_PROGRAM_FILES ' [Version 5.0] Program Files folder. A typical path is C:\Program Files. ' 'CSIDL_PROGRAM_FILESX86 ' Program Files folder for x86 apps on Alpha systems ' 'CSIDL_PROGRAM_FILES_COMMON ' [Version 5.0] A folder for components that are shared across applications. ' A typical path is C:\Program Files\Common. Valid only for Windows NT® and ' Windows® 2000 systems. ' 'CSIDL_PROGRAMS ' File system directory that contains the user's program groups (which are ' also file system directories). A typical path is C:\Documents and ' Settings\username\Start Menu\Programs. ' 'CSIDL_RECENT ' File system directory that contains the user's most recently used ' documents. A typical path is C:\Documents and Settings\username\Recent. ' To create a shortcut in this folder, use SHAddToRecentDocs. In addition to ' creating the shortcut, this function updates the shell's list of recent ' documents and adds the shortcut to the Documents submenu of the Start menu. ' 'CSIDL_SENDTO ' File system directory that contains Send To menu items. A typical path is ' C:\Documents and Settings\username\SendTo. ' 'CSIDL_STARTMENU ' File system directory containing Start menu items. A typical path is ' C:\Documents and Settings\username\Start Menu. ' 'CSIDL_STARTUP ' File system directory that corresponds to the user's Startup program group. ' The system starts these programs whenever any user logs onto Windows NT® ' or starts Windows® 95. A typical path is C:\Documents and ' Settings\username\Start Menu\Programs\Startup. ' 'CSIDL_SYSTEM ' [Version 5.0] System folder. A typical path is C:\WINNT\SYSTEM32. ' 'CSIDL_SYSTEMx86 ' System folder for x86 applications on Alpha systems ' 'CSIDL_TEMPLATES ' File system directory that serves as a common repository for document ' templates. ' 'CSIDL_WINDOWS ' [Version 5.0] Windows directory or SYSROOT. This corresponds to the %windir% ' or %SYSTEMROOT% environment variables. A typical path is C:\WINNT. ' 'See Also : '========== 'SHGetFolderLocation , SHGetFolderPath, SHGetSpecialFolderLocation, SHGetSpecialFolderPath '________________________________________________________________________________ 'DLL Version Numbers: '==================== ' 'All but a handful of the programming elements discussed in the shell and common 'controls documentation are contained in three DLLs: Comctl32.dll, Shell32.dll, 'and Shlwapi.dll. Because of ongoing enhancements, different versions of these 'DLLs implement different features. Throughout this document, programming 'elements are marked with a version number. This version number indicates that 'the programming element was first implemented in that version and will also be 'found in all subsequent versions of the DLL. If no version number is specified, 'the programming element is implemented in all versions. The following table 'outlines the different DLL versions, and how they were distributed. ' ' Version: DLL: Distribution Platform: '-------------------------------------------------------------------------------- ' 4.00 All Microsoft® Windows® 95/Windows NT® 4.0 ' 4.70 All Microsoft® Internet Explorer 3.x ' 4.71 All Microsoft® Internet Explorer 4.0 (see note 2) ' 4.72 All Microsoft® Internet Explorer 4.01 & Windows® 98 (see note 2) ' 5.00 Shlwapi.dll Microsoft® Internet Explorer 5 (see note 3) ' 5.00 Shell32.dll Microsoft® Windows® 2000 (see note 3) ' 5.80 Comctl32.dll Microsoft® Internet Explorer 5 (see note 3) ' 5.81 Comctl32.dll Microsoft® Windows 2000 (see note 3) ' ' 'Note 1: The 4.00 versions of Shell32.dll and Comctl32.dll are found on the 'original versions of Windows 95 and Windows NT 4. New versions of Commctl.dll 'were shipped with all Internet Explorer releases. Shlwapi.dll first shipped 'with Internet Explorer 4.0, so its first version number is 4.71. The shell 'was not updated with the Internet Explorer 3.0 release, so Shell32.dll does 'not have a version 4.70. While Shell32.dll versions 4.71 and 4.72 were 'shipped with the corresponding Internet Explorer releases, they were not 'necessarily installed (see Note 2). For subsequent releases, the version 'numbers for the three DLLs are not identical. In general, you should assume 'that all three DLLs may have different version numbers, and test each one 'separately. ' 'Note 2: All systems with Internet Explorer 4.0 or 4.01 will have the 'associated version of Comctl32.dll and Shlwapi.dll (4.71 or 4.72, 'respectively). However, for systems prior to Windows 98, Internet Explorer '4.0 and 4.01 can be installed with or without the integrated shell. If they 'are installed with the integrated shell, the associated version of 'Shell32.dll will be installed. If they are installed without the integrated 'shell, Shell32.dll is not updated. In other words, the presence of version '4.71 or 4.72 of Comctl32.dll or Shlwapi.dll on a system does not guarantee 'that Shell32.dll has the same version number. All Windows 98 systems have 'version 4.72 of Shell32.dll. ' 'Note 3:Version 5.80 of Comctl32.dll and version 5.0 of Shlwapi.dll are 'distributed with Internet Explorer 5. They will be found on all systems on 'which Internet Explorer 5 is installed, except Windows 2000. Internet 'Explorer 5 does not update the shell, so version 5.0 of Shell32.dll will not 'be found on Windows NT, Windows 95, or Windows 98 systems. Version 5.0 of 'Shell32.dll will be distributed with Windows 2000, along with version 5.0 'of Shlwapi.dll, and version 5.81 of Comctl32.dll.