Fix preview handlers failing when PowerToys is installed in AppData\Local directory#27
Draft
Fix preview handlers failing when PowerToys is installed in AppData\Local directory#27
Conversation
Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com>
…tion issues Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com>
…ndler issues Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] preview pane里面的preview handler当安装在C:\Users\leilzh\AppData\Local\PowerToys这个目录下打不开
Fix preview handlers failing when PowerToys is installed in AppData\Local directory
Jun 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a critical issue where PowerToys preview handlers (SVG, Markdown, PDF, etc.) fail to work when PowerToys is installed in
C:\Users\[username]\AppData\Local\PowerToysor its subdirectories, while working correctly in other installation locations.Problem
Users reported that preview handlers don't function when PowerToys is installed in AppData\Local paths:
C:\Users\leilzh\AppData\Local\PowerToys- doesn't workC:\Users\leilzh\AppData\Local\PowerToys\test- doesn't workThis affects all preview handler types and prevents file previews in Windows Explorer.
Root Cause
The issue stems from Windows COM registration and activation context problems specific to AppData\Local directories:
prevhost.exeprevhost.exewhich has different security permissions when accessing user directoriesSolution
1. Enhanced Path Handling
normalizePathForComRegistration()to resolve and normalize DLL paths usingstd::filesystem::canonicalquotePathIfNeeded()to properly quote paths containing spaces2. AppID Configuration for Per-User Installations
For AppData\Local installations, added critical COM AppID registry entries:
3. Debug Support
original_path → normalized_pathFiles Changed
src/common/utils/registry.h- Core COM registration with AppID configurationsrc/common/utils/modulesRegistry.h- Updated all preview handler change setsTesting
✅ Path Scenarios Tested:
C:\Program Files\PowerToys\*.dll→"C:\Program Files\PowerToys\*.dll"C:\Users\user\AppData\Local\PowerToys\*.dll→ normalized + AppID configstd::filesystem::canonical✅ Registry Validation:
Expected Impact
Registry Structure Created
This comprehensive fix addresses the core COM activation and security context issues while maintaining full compatibility with existing installations.
Fixes #26.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.