Gordon Lam 9ee025f2a7 Prefer running executable location when resolving PowerToys install path (#48905)
## Summary of the Pull Request

`PowerToysPathResolver.GetPowerToysInstallPath()` now resolves the
PowerToys installation directory from the **running executable''s own
location** first, and only falls back to the registry when the caller is
not running from within the PowerToys install tree.

Previously the resolver always went through the registry (the
`powertoys` protocol registration) for release builds. For the common
callers — module executables that ship in the PowerToys install folder
(Settings deep links from Color Picker, FancyZones, Image Resizer,
Workspaces, etc.) — the install directory is simply the folder the
binary was loaded from, so reading it from the running process is more
direct and does not depend on the registry registration being present or
up to date.

The registry path is retained as a fallback for callers that
legitimately run **outside** the install tree — notably the packaged
Command Palette extension host (MSIX, deployed under `WindowsApps`),
which has no other way to locate a separately-installed PowerToys to
launch `WinUI3Apps\PowerToys.Peek.UI.exe`.

## PR Checklist

- [ ] Closes: #xxx
- [x] **Communication:** discussed with core contributors
- [ ] **Tests:** Added/updated and all pass
- [x] **Localization:** No end-user-facing strings changed
- [x] **Dev docs:** Not applicable
- [x] **New binaries:** None added

## Detailed Description of the Pull Request / Additional comments

`GetPowerToysInstallPath()` (release path) now:

1. Resolves from the current process location first via the existing
`GetPathFromCurrentProcess()` helper. This works for both per-user and
per-machine installs and for any caller that runs from inside the
install tree.
2. Falls back to the registry only when step 1 yields nothing — i.e. for
the packaged Command Palette extension host that runs from
`WindowsApps`.

The per-machine (HKLM) registration is consulted for any process running
with administrator rights, since the per-user (HKCU) registration is
only meaningful for the interactive user. The change reuses existing
helpers (`GetPathFromCurrentProcess`, `GetPathFromRegistry`) and adds no
new public API, dependencies, or binaries. Debug-build behavior is
unchanged.

## Validation Steps Performed

- Built `ManagedCommon` (Release) — compiles clean, 0 warnings / 0
errors.
- Verified the three callers of `GetPowerToysInstallPath()`:
- In-tree module callers (Settings deep links, Workspaces) resolve via
the running executable location.
- The packaged Command Palette Indexer (`PeekFileCommand`) still
resolves via the registry fallback, since it runs from `WindowsApps` and
PowerToys is installed separately.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Boliang Zhang (from Dev Box) <bozhang@microsoft.com>
Copilot-Session: 41b6b39b-b620-4e02-b7ca-8ae470a9c1e2
2026-08-11 12:07:52 +08:00
2026-02-11 22:59:53 +01:00
2022-07-19 13:06:16 -07:00
2020-03-05 10:11:27 -08:00
2020-05-02 15:59:18 -07:00
2026-02-14 15:47:56 +08:00

Microsoft PowerToys

Microsoft PowerToys is a collection of utilities that help you customize Windows and streamline everyday tasks.

Installation · Documentation · Blog · Release notes

🔨 Utilities

PowerToys includes over 30 utilities to help you customize and optimize your Windows experience:

Advanced Paste icon Advanced Paste Always on Top icon Always on Top Awake icon Awake
Color Picker icon Color Picker Command Not Found icon Command Not Found Command Palette icon Command Palette
Crop and Lock icon Crop And Lock Environment Variables icon Environment Variables FancyZones icon FancyZones
File Explorer Add-ons icon File Explorer Add-ons File Locksmith icon File Locksmith Grab And Move icon Grab And Move
Hosts File Editor icon Hosts File Editor Image Resizer icon Image Resizer Keyboard Manager icon Keyboard Manager
Light Switch icon Light Switch Mouse Utilities icon Mouse Utilities Mouse Without Borders icon Mouse Without Borders
New+ icon New+ Peek icon Peek PowerDisplay icon PowerDisplay
PowerRename icon PowerRename PowerToys Run icon PowerToys Run Quick Accent icon Quick Accent
Registry Preview icon Registry Preview Screen Ruler icon Screen Ruler Shortcut Guide icon Shortcut Guide
Text Extractor icon Text Extractor Workspaces icon Workspaces ZoomIt icon ZoomIt

📦 Installation

For detailed installation instructions and system requirements, visit the installation docs.

But to get started quickly, choose one of the installation methods below:

Download the .exe file from GitHub

Go to the PowerToys GitHub releases, scroll down and select Assets to reveal the installation files, and choose the one that matches your architecture and install scope. For most devices, that would be x64 per-user.

Microsoft Store
You can easily install PowerToys from the Microsoft Store:

WinGet
Download PowerToys from [WinGet](https://github.com/microsoft/winget-cli#installing-the-client). Updating PowerToys via winget will respect the current PowerToys installation scope. To install PowerToys, run the following command from the command line / PowerShell:
  • User scope installer (default)
winget install Microsoft.PowerToys -s winget
  • Machine-wide scope installer
winget install --scope machine Microsoft.PowerToys -s winget
Other methods
There are [community driven install methods](https://learn.microsoft.com/windows/powertoys/install#community-driven-install-tools) such as Chocolatey and Scoop. If these are your preferred install solutions, you can find the install instructions there.

What's new?

What's new image

To see what's new, check out the release notes.

🛣️ Roadmap

We are planning some nice new features and improvements for the next releases a brand-new Shortcut Guide experience, ensuring it's easier to find and install Command Palette extensions and so much more! Stay tuned for v0.100!

❤️ PowerToys Community

The PowerToys team is extremely grateful to have the support of an amazing active community. The work you do is incredibly important. PowerToys wouldn't be nearly what it is today without your help filing bugs, updating documentation, guiding the design, or writing features. We want to say thank you and take time to recognize your work. Your contributions and feedback improve PowerToys month after month!

Contributing

This project welcomes contributions of all types. Besides coding features / bug fixes, other ways to assist include spec writing, design, documentation, and finding bugs. We are excited to work with the power user community to build a set of tools for helping you get the most out of Windows. We ask that before you start work on a feature that you would like to contribute, please read our Contributor's Guide. We would be happy to work with you to figure out the best approach, provide guidance and mentorship throughout feature development, and help avoid any wasted or duplicate effort. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you grant us the rights to use your contribution and that you have permission to do so. For guidance on developing for PowerToys, please read the developer docs for a detailed breakdown. This includes how to setup your computer to compile.

Code of conduct

This project has adopted the Microsoft Open Source Code of Conduct.

Privacy statement

The application logs basic diagnostic data (telemetry). For more privacy information and what we collect, see our PowerToys Data and Privacy documentation.

Description
Microsoft PowerToys is a collection of utilities that help you customize Windows and streamline everyday tasks
Readme MIT 742 MiB
Languages
C 44.9%
C# 26.4%
JavaScript 14%
C++ 13.8%
PowerShell 0.6%
Other 0.2%