Results 1 to 13 of 13

Thread: Here is a little code snippet if you feel for manage your so called "Known Folders"

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    976

    Here is a little code snippet if you feel for manage your so called "Known Folders"

    As the the title says. Manage your known folders by enabling IKnownFolderManager Interface.
    I have not yet tried all methodes but it seems really useful and powerfull.
    For example setting up your own "Control Panel" for management of all the known folders.
    And for example use GetFolder method to retrieve indvidual IKnownFolder and configure them as well.
    Also I have named the function in "MS Shellish way"
    Enough with explaining
    Go ahead and play around but BE AWARE!! ALL CHANGES ARE PERMANENT!!
    Code:
    'This will remove EVERYTHING in your Library folder and add in this case "D:\" drive
    
    Private Sub Command4_Click()
      Dim pIKFM As IKnownFolderManager
      Dim pIKF As IKnownFolder
      Dim lpGUID As UUID
        
      ShGetIKnownFolderManager pIKFM
      'Libraries Main Folder
      IIDFromString StrPtr("{1B3EA5DC-B587-4786-B4EF-BD1DC332AEAE}"), lpGUID
      pIKFM.GetFolder lpGUID, pIKF
      If Not pIKF Is Nothing Then
        pIKF.SetPath KF_FLAG_DEFAULT, "D:\"
      End If
    End Sub
    
    Public Function ShGetIKnownFolderManager(pIKFM As IKnownFolderManager) As Long
      Static CLSID_KnownFolderManager As GUID
      
      Dim hr As Long
      
      hr = GuidFromStringW(StrPtr("{4df0c730-df9d-4ae3-9153-aa6b82e9795a}"), CLSID_KnownFolderManager)
      hr = CoCreateInstance(CLSID_KnownFolderManager, 0, CLSCTX_INPROC_SERVER, IID_IKnownFolderManager, pIKFM)
      
      If hr = S_OK Then
        ShGetIKnownFolderManager = S_OK
      Else
        ShGetIKnownFolderManager = hr
      End If
    End Function
    Depending on how old your system is you can use one of these two API's for converting the "bracket guid strings" to GUID Types.
    I use the Unicode version (W).

    Code:
    Public Declare Function GuidFromStringA Lib "shell32.dll" Alias "#703" (ByVal pszGUID As String, ByRef pguid As GUID) As Long
    Public Declare Function GuidFromStringW Lib "shell32.dll" Alias "#704" (ByVal pszGUID As Long, ByRef pguid As GUID) As Long
    Here is the MSDN documentation for this interface.

    https://learn.microsoft.com/en-us/wi...nfoldermanager

    Cheers

    /Kent
    Last edited by nebeln; Jan 10th, 2024 at 03:22 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