Skip to content

New+: Fix "Open templates folder" failing when PowerToys runs as a different admin account#47393

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-templates-folder-access
Draft

New+: Fix "Open templates folder" failing when PowerToys runs as a different admin account#47393
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-templates-folder-access

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

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). ShellExecuteEx with UseShellExecute = true on a directory path dispatches through the interactive shell session of the logged-in user, not the elevated account — so it tries to open C:\Users\<logged-in-user>\... instead of C:\Users\<runas-user>\....

Summary of the Pull Request

  • NewPlusViewModel.csOpenNewTemplateFolder(): Replaced ProcessStartInfo { FileName = path, UseShellExecute = true } with an explicit explorer.exe invocation using a fully-qualified path and a properly quoted argument:
// Before
var process = new ProcessStartInfo() { FileName = _templateLocation, UseShellExecute = true };
Process.Start(process);

// After
private static readonly string ExplorerExePath =
    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");

Process.Start(new ProcessStartInfo
{
    FileName = ExplorerExePath,
    Arguments = $"\"{templateLocation}\"",
});
  • Explorer is resolved from Environment.SpecialFolder.Windows so there is no reliance on PATH search semantics, avoiding potential search-order hijacking.
  • The template folder path is wrapped in double-quotes so folders with spaces (e.g. Documents\My Templates) open correctly.
  • A unit test (ViewModelTests/NewPlus.cs) was added to verify that CreateExplorerProcessStartInfo produces the correct fully-qualified FileName and a properly quoted Arguments string.

PR Checklist

  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Spawning explorer.exe directly 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

  • Manually verified the folder opens correctly when launching PowerToys normally.
  • The root cause (wrong shell token under runas) is addressed by design: launching explorer.exe via ProcessStartInfo inherits the process token rather than delegating to the interactive shell.
  • Unit test CreateExplorerProcessStartInfoShouldQuoteTemplatePathAndUseFullExplorerPath passes, asserting both the fully-qualified FileName and the quoted Arguments for a path containing spaces.

…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>
Copilot AI changed the title [WIP] Fix templates folder access issue when running PowerToys as administrator New+: Fix "Open templates folder" failing when PowerToys runs as a different admin account Apr 29, 2026
Copilot AI requested a review from MuyuanMS April 29, 2026 10:31
@niels9001 niels9001 added the Product-New+ Refers to the New+ PowerToys Utility label Apr 29, 2026
@MuyuanMS MuyuanMS requested a review from Copilot May 14, 2026 03:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 launch explorer.exe targeting the configured template directory.

UseShellExecute = true,
};
Process.Start(process);
Process.Start("explorer.exe", _templateLocation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@MuyuanMS
Copy link
Copy Markdown
Contributor

@copilot please re-review the latest changes.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot please re-review the latest changes.

Reviewed commit a3f8d78. The changes look good:

  • ExplorerExePath is resolved at class-initialization time from Environment.SpecialFolder.Windows, so there's no PATH-search risk.
  • CreateExplorerProcessStartInfo wraps the path in double-quotes, handling folders with spaces correctly.
  • The unit test in ViewModelTests/NewPlus.cs covers both the fully-qualified FileName and the quoted Arguments assertions.

No further issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-New+ Refers to the New+ PowerToys Utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't open up templates folder when running PowerToys as administrator (as another account)

4 participants