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" :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 ;)
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Quote:
Originally Posted by
nebeln
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
Declaring API functions by ordinal is fairly unsafe. Except for a select few libraries that remained unchanged over the decades, most others have been constantly updated from one version of Windows to the next (mainly by adding new functions) and so the ordinals change and your code will break.
You can easily test this by running your program in Windows 10 and 11 since these are currently the most relevant operating systems.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
I have test runed both theese two API's on this current machine which is Win10 Pro and for me the A version not working = faults in next API CoCreateInstance but with W version CoCreateInstance returns S_OK.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Quote:
Originally Posted by
nebeln
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 ;)
Why choose a function that is only exported by ordinal and may not be supported beyond Vista according to the docs https://learn.microsoft.com/en-us/wi...guidfromstring when the documentation even suggest two other supported ways of doing this?
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Hi
Thank for asking...I did this totally willingly because I wanted to be "in the shell" since the the API's are exported from the Shell32.
Yes, for sure you can use IIDFromString or CLSIDFromString if you feel that more secure.
/Kent
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Quote:
Originally Posted by
nebeln
Hi
Thank for asking...I did this totally willingly because I wanted to be "in the shell" since the the API's are exported from the Shell32.
Yes, for sure you can use IIDFromString or CLSIDFromString if you feel that more secure.
/Kent
Nothing to do with security, simply that the documentation itself recommends using one of the other functions instead.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
But as long as my stated API's do the deed's there is no worry...so feel free to change API :wave:
/Kent
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
It can be a "False true" because if you check the "contributors"..they are writing this, not MS...so there is a little bit as "Wikipedia" :wave:
And if you double check with Geoff Chapell - he never says that GUIDFromString should be swapped with IID or CLSID.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Quote:
Originally Posted by
nebeln
It can be a "False true" because if you check the "contributors"..they are writing this, not MS...so there is a little bit as "Wikipedia" :wave:
It is the official MS documentation, it is most certainly not just like Wikipedia - if you check those 5 contributors then at least 4 of them are MS employees.
I just think it is generally good practice to show code samples that use the recommended, and supported, functionality when such functionality exists.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
As I told I did this total deliberatily even if I knew the recommenadtions because I wanted to keep it inside "the shell" :)
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
If you have those interfaces defined, it's presumably because you have oleexp. So why not use this:
Code:
Dim pIKFM As IKnownFolderManager
Dim pIKF As IKnownFolder
Set pIKFM = New KnownFolderManager
pIKFM.GetFolder FOLDERID_Libraries, pIKF
Dropping in mIID.bas makes sure virtually none of the shell programming IIDs, FOLDERIDs, etc, need 5 minutes spent duplicating the effort for every one. Then you don't need to use an API *at all*.
As long as you're not nebeln with a project requirement of 'no matter how inconvenient, make sure not to do things the standard way, especially if fafalone does", I'd strongly recommend the above approaches.
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
By doing as you explain, then you’re exactly as Schmith but with you as a header text and not MS 🤣
Re: Here is a little code snippet if you feel for manage your so called "Known Folder
Yeah I'm not telling to you use an opaque binary blob with less functionality, but thanks for telling me how little you understand, well, anything I say, anything Schimdt says, or how any of this all really works. Class wrappers aren't the same as coclass declarations and predefined UUIDs.
The equivalent here would be if I had suggested using shell32.Shell's special folder functionality.