PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

CmdPal: Applications are launched with an outdated PATH

Open lpaulino07 opened this issue 1 year ago • 9 comments

Microsoft PowerToys version

0.94.2

Installation method

WinGet

Area(s) with issue?

Command Palette

Steps to reproduce

  • Launch PowerToys.
  • Add binary to PATH (i.e. install something like Swift that updates PATH for new binaries).
  • Launch VS Code
  1. Through CmdPal: swift Will not be recognized.
  2. Through Powershell or Start Menu: swift Will be recognized.

✔️ Expected Behavior

A new CmdPal-launched process should have access to an updated PATH.

❌ Actual Behavior

Processes are launched with outdated PATH unless PowerToys is restarted.

Additional Information

No response

Other Software

VS Code 1.106.0

lpaulino07 avatar Oct 11 '25 20:10 lpaulino07

I would consider this a standard expectation in most software- it must be restarted to recognize an updated PATH. Powershell also will not recognize swift if it was launched prior to updating your PATH.

samrueby avatar Oct 12 '25 03:10 samrueby

Understandable. Just wanted to report it in case it wasn't expected behavior.

lpaulino07 avatar Oct 12 '25 15:10 lpaulino07

@lpaulino07 Great point! Since Command Palette runs as a persistent process and launcher, it should keep its PATH environment variable up to date to ensure newly installed tools are immediately accessible without the need to restart itself.

jiripolasek avatar Oct 12 '25 18:10 jiripolasek

I would agree that the expected behavior would be for Command Palette to mirror the behavior of another launcher like the start menu itself, since it is supposed to be able to replace the start menu IMO.

nWestie avatar Mar 09 '26 16:03 nWestie

Will start work on this, aiming to have a fix within the week

csbehrend avatar Apr 21 '26 23:04 csbehrend

PowerToys: 0.102.3101.0 Zed: 1.28.1 stable Windows: Windows 11 Home 26H2, build 26300.9974 Integrated shell: PowerShell 7.7.0

Just wanted to throw my own details on this here. I ran through having PowerToys launched with both non-administrator and administrator privileges. Both administrator and non-administrator runs produced identical results; Start picked up the change, Command Palette stayed stale until PowerToys restarted.

Reproduction transcript - PowerToys running without administrator privileges

Establish baseline setup

Variable changed through the settings GUI:

  • Start
  • Search enrionment variables
  • Select Edit environment variables for your account
  • Add new user variable name: CMDPAL_ENV_PROBE value: before
  • Click ok button to close the variable edit pop-up
  • Click ok button to close the Environment variables window
  • Ensure Zed and PowerToys are fully quit
  • Launch PowerToys

Zed Launched Via Command Palette - Baseline

PS C:\Users\Username> Get-Date -Format o
2026-11-17T14:41:55.5438126-05:00
PS C:\Users\Username> $env:CMDPAL_ENV_PROBE
before
PS C:\Users\Username> [Environment]::GetEnvironmentVariable('CMDPAL_ENV_PROBE', 'User')
before

Zed Fully Closed - Environment Variable Updated - Zed Relaunched Via Command Palette

CMDPAL_ENV_PROBE value: before changed to CMDPAL_ENV_PROBE value: after within the settings GUI. Clicking ok on the edit pop-up, and ok on the Environment variables window.

PS C:\Users\Username> Get-Date -Format o
2026-11-17T14:43:23.3121176-05:00
PS C:\Users\Username> $env:CMDPAL_ENV_PROBE
before
PS C:\Users\Username> [Environment]::GetEnvironmentVariable('CMDPAL_ENV_PROBE', 'User')
after

Zed Fully Closed - Zed Relaunched Via Start Menu

PS C:\Users\Username> Get-Date -Format o
2026-11-17T14:44:33.7994437-05:00
PS C:\Users\Username> $env:CMDPAL_ENV_PROBE
after
PS C:\Users\Username> [Environment]::GetEnvironmentVariable('CMDPAL_ENV_PROBE', 'User')
after

Zed Fully Closed - Zed Relaunched Via Command Palette(again)

PS C:\Users\Username> Get-Date -Format o
2026-11-17T14:45:10.0506893-05:00
PS C:\Users\Username> $env:CMDPAL_ENV_PROBE
before
PS C:\Users\Username> [Environment]::GetEnvironmentVariable('CMDPAL_ENV_PROBE', 'User')
after

Zed Fully Closed PowerToys Fully Closed + Re-Launched - Zed Relaunched Via Command Palette

PS C:\Users\Username> Get-Date -Format o
2026-11-17T14:46:18.3181506-05:00
PS C:\Users\Username> $env:CMDPAL_ENV_PROBE
after
PS C:\Users\Username> [Environment]::GetEnvironmentVariable('CMDPAL_ENV_PROBE', 'User')
after

redrix-dev avatar Nov 17 '26 20:11 redrix-dev

Will start work on this, aiming to have a fix within the week

It's been like 7 months or so, I got busy lol. From the time I did take a look at it, found two practical solutions, just haven't implemented.

  1. WM_SETTING­CHANGED - Have CmdPal listen for the settings update window message like explorer does, and update PATH manually.
  2. Explorer COM Magic - Use COM to have explorer launch the program for us. Would mimic start menu more closely.

Each has its own downsides, but good leads IMO.

csbehrend avatar Nov 17 '26 21:11 csbehrend

Will start work on this, aiming to have a fix within the week

It's been like 7 months or so, I got busy lol. From the time I did take a look at it, found two practical solutions, just haven't implemented.

1. [WM_SETTING­CHANGED](https://devblogs.microsoft.com/oldnewthing/20150915-00/?p=91591/) - Have CmdPal listen for the settings update window message like explorer does, and update PATH manually.

2. [Explorer COM Magic](https://devblogs.microsoft.com/oldnewthing/20131118-00/?p=2643/) - Use COM to have explorer launch the program for us. Would mimic start menu more closely.

Each has its own downsides, but good leads IMO.

Precedent for option 1 already in Powertoys Run

csbehrend avatar Nov 17 '26 21:11 csbehrend

Will start work on this, aiming to have a fix within the week

It's been like 7 months or so, I got busy lol. From the time I did take a look at it, found two practical solutions, just haven't implemented.

1. [WM_SETTING­CHANGED](https://devblogs.microsoft.com/oldnewthing/20150915-00/?p=91591/) - Have CmdPal listen for the settings update window message like explorer does, and update PATH manually.

2. [Explorer COM Magic](https://devblogs.microsoft.com/oldnewthing/20131118-00/?p=2643/) - Use COM to have explorer launch the program for us. Would mimic start menu more closely.

Each has its own downsides, but good leads IMO.

Precedent for option 1 already in Powertoys Run

For what it's worth, I did some digging through Command Palette's launch path earlier and found a few things that might be useful:

  1. All Apps runs inside the Command Palette UI process. The built-in application provider is instantiated directly in App.xaml.cs.

  2. Desktop applications launch through Process.Start(). In AppCommand.cs, the launch path uses UseShellExecute = true, without an explicit environment refresh beforehand.

  3. Command Palette already handles WM_SETTINGCHANGE. However, the handler in MainWindow.xaml.cs appears to handle font/icon metrics rather than environment changes.

I also came across the existing PowerToys Run implementation in EnvironmentHelper.UpdateEnvironment(), which handles merging machine/user variables, deleted variables, process-specific overrides, and variable expansion.

That looks like a useful precedent for option 1. One caveat is that refreshing Command Palette's own environment may not be sufficient by itself: with UseShellExecute = true, the resulting environment depends on the shell execution path and whether it uses Command Palette's updated environment or delegates launching elsewhere.

I haven't tested a patch or verified that propagation behavior, but the existing message handler and PowerToys Run helper seem like reasonable starting points.

redrix-dev avatar Nov 17 '26 22:11 redrix-dev