Results 1 to 15 of 15

Thread: VB6: Windows 10 Known Folders / SHGetKnownFolderPath

Threaded View

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    VB6: Windows 10 Known Folders / SHGetKnownFolderPath

    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
    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 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
    The order of the enumerated values doesn't matter, so feel free to pick and choose any of the virtual folders to include by moving them above the compiler directive. Be sure to make the same change to the two functions: KnownFolderGUID() and KnownFolderName(). Alternately, you could move many (most?) of the values to inside the directive to streamline the enumerated list, showing only those values you might actually need.
    Attached Files Attached Files
    Last edited by Ellis Dee; May 15th, 2016 at 06:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width