New+: Fix "Open templates folder" failing when PowerToys runs as a different admin account#47393
New+: Fix "Open templates folder" failing when PowerToys runs as a different admin account#47393Copilot wants to merge 3 commits into
Conversation
…n running as different admin user Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/481445da-c05e-4da6-af6c-07c83ecbf675 Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes New+ Settings “Open templates folder” failing when PowerToys is launched via Run as different user by avoiding shell-dispatch on a directory path and instead invoking Explorer directly under the current process token.
Changes:
- Update
OpenNewTemplateFolder()to launchexplorer.exetargeting the configured template directory.
| UseShellExecute = true, | ||
| }; | ||
| Process.Start(process); | ||
| Process.Start("explorer.exe", _templateLocation); |
There was a problem hiding this comment.
Fixed — OpenNewTemplateFolder now launches Explorer through a ProcessStartInfo built with a fully-qualified %WINDIR%\\explorer.exe path, and the template folder argument is explicitly quoted so folders with spaces open correctly. I also added a unit test covering both behaviors.
| UseShellExecute = true, | ||
| }; | ||
| Process.Start(process); | ||
| Process.Start("explorer.exe", _templateLocation); |
There was a problem hiding this comment.
Fixed — the new helper resolves Explorer from Environment.SpecialFolder.Windows and uses that fully-qualified path in ProcessStartInfo, so we no longer rely on explorer.exe search semantics. Added a unit test for the generated start info as well.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot please re-review the latest changes. |
Reviewed commit
No further issues found. |
Clicking the templates folder button in New+ settings fails with "Location is not available" when PowerToys is launched via Run as different user (e.g., a bang/admin account).
ShellExecuteExwithUseShellExecute = trueon a directory path dispatches through the interactive shell session of the logged-in user, not the elevated account — so it tries to openC:\Users\<logged-in-user>\...instead ofC:\Users\<runas-user>\....Summary of the Pull Request
NewPlusViewModel.cs—OpenNewTemplateFolder(): ReplacedProcessStartInfo { FileName = path, UseShellExecute = true }with an explicitexplorer.exeinvocation using a fully-qualified path and a properly quoted argument:Environment.SpecialFolder.Windowsso there is no reliance on PATH search semantics, avoiding potential search-order hijacking.Documents\My Templates) open correctly.ViewModelTests/NewPlus.cs) was added to verify thatCreateExplorerProcessStartInfoproduces the correct fully-qualifiedFileNameand a properly quotedArgumentsstring.PR Checklist
Detailed Description of the Pull Request / Additional comments
Spawning
explorer.exedirectly inherits the current process token (the runas account), so the correct user's AppData path is accessible. There is no behavioral change for the normal (same-user) case — the folder opens identically. The fix is purely about which user token backs the shell dispatch.Using a fully-qualified path (
%WINDIR%\explorer.exe) instead of relying on"explorer.exe"name resolution eliminates any risk of executable search-order hijacking if the working directory or PATH is influenced.Validation Steps Performed
ProcessStartInfoinherits the process token rather than delegating to the interactive shell.CreateExplorerProcessStartInfoShouldQuoteTemplatePathAndUseFullExplorerPathpasses, asserting both the fully-qualifiedFileNameand the quotedArgumentsfor a path containing spaces.