Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

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

$
0
0
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" :D
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 :wave:

/Kent ;)

Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>