Download the bas module here: basKnownFolders.bas
In Windows XP, the recommended practice to find special folders was to call SHGetFolderPath(), but this was deprecated starting in Windows Vista. From Vista on, we're supposed to use SHGetKnownFolderPath(). Unfortunately, it's extremely hard to find easy-to-use code for SHGetKnownFolderPath without having to add unnecessary references or components to your project. (typelibs, or scripting objects.)
Thanks to Randy Birch's excellent sample code, here's an easy-to-use module that lets you identify special folders using API calls, no references or components needed. Simply add the attached module to your project, then call the following function:
?KnownFolder(enumerated value)
You can call the following from the debug window to see a list of known folders and their values:
KnownFolderList
The module contains two compiler directives:
Of the 88 total known folders, only 54 return any value for me. The rest are listed as virtual folders by Randy Birch's sample project. I've moved these 34 virtual folders to the end of the enumeration and wrapped them in compiler directives, letting you easily prevent them from being included. This helps reduce clutter in the enumeration dropdown.
The second compiler directive lets you discard the KnownFoldersList() debug window output routines to reduce the size of the code in your finished project.
Here's a the known folder enumeration for reference:
In Windows XP, the recommended practice to find special folders was to call SHGetFolderPath(), but this was deprecated starting in Windows Vista. From Vista on, we're supposed to use SHGetKnownFolderPath(). Unfortunately, it's extremely hard to find easy-to-use code for SHGetKnownFolderPath without having to add unnecessary references or components to your project. (typelibs, or scripting objects.)
Thanks to Randy Birch's excellent sample code, here's an easy-to-use module that lets you identify special folders using API calls, no references or components needed. Simply add the attached module to your project, then call the following function:
?KnownFolder(enumerated value)
You can call the following from the debug window to see a list of known folders and their values:
KnownFolderList
The module contains two compiler directives:
Code:
#Const IncludeVirtualFolders = False
#Const IncludeDebugListing = True
The second compiler directive lets you discard the KnownFoldersList() debug window output routines to reduce the size of the code in your finished project.
Here's a the known folder enumeration for reference:
Code:
Public Enum KnownFolderEnum
kfUserProfiles
kfUser
kfUserDocuments
kfUserContacts
kfUserDesktop
kfUserDownloads
kfUserMusic
kfUserPictures
kfUserSavedGames
kfUserVideos
kfUserAppDataRoaming
kfUserAppDataLocal
kfUserAppDataLocalLow
kfUserCDBurning
kfUserCookies
kfUserFavorites
kfUserGameTasks
kfUserHistory
kfUserInternetCache
kfUserLinks
kfUserNetHood
kfUserPrintHood
kfUserQuickLaunch
kfUserRecent
kfUserSavedSearches
kfUserSendTo
kfUserStartMenu
kfUserStartMenuAdminTools
kfUserStartMenuPrograms
kfUserStartMenuStartup
kfUserTemplates
kfPublic
kfPublicDesktop
kfPublicDocuments
kfPublicDownloads
kfPublicMusic
kfPublicPictures
kfPublicVideos
kfPublicStartMenu
kfPublicStartMenuAdminTools
kfPublicStartMenuPrograms
kfPublicStartMenuStartup
kfPublicGameTasks
kfPublicTemplates
kfProgramData
kfWindows
kfSystem
kfSystemX86
kfSystemFonts
kfSystemResourceDir
kfProgramFilesX86
kfProgramFilesCommonX86
kfProgramFiles
kfProgramFilesCommon
#If IncludeVirtualFolders = True Then
kfAddNewPrograms
kfAppUpdates
kfChangeRemovePrograms
kfCommonOEMLinks
kfComputerFolder
kfConflictFolder
kfConnectionsFolder
kfControlPanelFolder
kfGames
kfInternetFolder
kfLocalizedResourcesDir
kfNetworkFolder
kfOriginalImages
kfPhotoAlbums
kfPlaylists
kfPrintersFolder
kfProgramFilesX64
kfProgramFilesCommonX64
kfRecordedTV
kfRecycleBinFolder
kfSampleMusic
kfSamplePictures
kfSamplePlaylists
kfSampleVideos
kfSEARCH_CSC
kfSEARCH_MAPI
kfSearchHome
kfSidebarDefaultParts
kfSidebarParts
kfSyncManagerFolder
kfSyncResultsFolder
kfSyncSetupFolder
kfTreeProperties
kfUsersFiles
#End If
#If IncludeDebugListing = True Then
kfKnownFolders
#End If
End Enum