This project focuses on creating a Windows shell extension for generating thumbnails. Writing shell extensions in .NET is opinionated but here we go. There are 3 interfaces that the thumbnail provider can use to initialize the thumbnail:
- IInitializeWithStream - file stream is passed in as an argument
- IInitializeWithFile - file path is passed in as an argument
- IInitializeWithItem - ShellItem is passed in as an argument
Microsoft suggests implementing the IInitializeWithStream interface - this way the shell extension runs out of process, providing extra security. To use IInitializeWithFile or IInitializeWithItem we need to opt out of the process isolation feature by setting the following registry value:
- HKEY_CLASSES_ROOT
- CLSID
- {Your thumbnail provider CLSID}
DisableProcessIsolation = 1 (DWORD)
Choose the interface that suits your needs best.
- Build the project
- Register the COM component
- Enjoy the new thumbnails 😎
regsvr32 is a tool used to register COM components. Registering the component will create two main keys inside the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{THUMBNAILPROVIDER_CLSID}
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\{ProgID}
To register the COM component:
regsvr32 "full\path\to\ThumbnailProvider.comhost.dll"
To unregister the COM component:
regsvr32 /u "full\path\to\ThumbnailProvider.comhost.dll"
ℹ️ Make sure you're executing these commands with elevated privileges.
ℹ️ If you're using DisableProcessIsolation = 1, the changes will be applied only after restarting the explorer.exe process.
For folks trying to make this work with Cloud Filter API:
- Implement the IInitializeWithItem interface (not IInitializeWithFile or IInitializeWithStream)
- Insert a string value pointing to your thumbnail provider CLSID:
- ...
- Windows
- CurrentVersion
- Explorer
- SyncRootManager
- [Your sync root id]
ThumbnailProvider = {THUMBNAILPROVIDER_CLSID}
That's it, from now on all file thumbnails under the sync root should be generated by our ThumbnailProvider.