This document describes how context menu handlers are implemented in PowerToys, covering both Windows 10 and Windows 11 approaches.
PowerToys implements two types of context menu handlers:
-
Old-Style Context Menu Handlers
- Used for Windows 10 compatibility
- Registered via registry entries
- Implemented as COM objects exposing the
IContextMenuinterface - Registered for specific file extensions
-
Windows 11 Context Menu Handlers
- Implemented as sparse MSIX packages
- Exposing the
IExplorerCommandinterface - Located in
PowerToys\x64\Debug\modules\<module>\<module>.msix - Registered for all file types and filtered in code
- Requires signing to be installed
PowerToys modules use two different approaches for registering context menu handlers:
- Both old-style and Windows 11 context menu handlers are registered
- Results in duplicate entries in Windows 11's expanded context menu
- Ensures functionality even if Windows 11 handler fails to appear
- Old-style handlers appear in the "Show more options" expanded menu
- Windows 10: Uses old-style context menu handler
- Windows 11: Uses new MSIX-based context menu handler
- Avoids duplicates but can cause issues if Windows 11 handler fails to register
- MSIX packages are defined in
AppManifest.xmlin each context menu project - Registration happens in
DllMainof the module interface DLL when the module is enabled - Explorer restart may be required after registration for changes to take effect
- Registration can be verified with
Get-AppxPackagePowerShell command:Get-AppxPackage -Name *PowerToys*
- Handlers implement the
IExplorerCommandinterface - Key methods:
GetState: Determines visibility based on file typeInvoke: Handles the action when the menu item is clickedGetTitle: Provides the text to display in the context menu
- For selective filtering (showing only for certain file types), the logic is implemented in the
GetStatemethod
- Build generates an MSIX package from the context menu project
- When the module is enabled, PowerToys installs the package using
PackageManager.AddPackageAsync - The package references the DLL that implements the actual context menu handler
- When the user right-clicks, Explorer loads the DLL and calls into its methods
- Update the registry to point to your debug build
- Restart Explorer
- Attach the debugger to explorer.exe
- Set breakpoints and test by right-clicking in File Explorer
- Build PowerToys to get the MSIX packages
- Sign the MSIX package with a self-signed certificate
- Replace files in the PowerToys installation directory
- Use PowerToys to install the package
- Restart Explorer
- Run Visual Studio as administrator
- Set breakpoints in relevant code
- Attach to DllHost.exe process when context menu is triggered
- Windows 11 handlers require signing and reinstalling for each code change
- DllHost loads the DLL only when context menu is triggered and unloads after
- For efficient development, use logging or message boxes instead of breakpoints
- Consider debugging the Windows 10 handler by removing OS version checks
- Context menu entries not showing in Windows 11
- Usually due to package not being removed/updated properly on PowerToys update
- Fix: Uninstall and reinstall the package or restart Explorer
- Registering packages requires signing
- For local testing, create and install a signing certificate
- Duplicate entries in Windows 11 context menu
- By design for some modules to ensure availability if Windows 11 handler fails