Why are changes to my PATH not being recognised?

39

3

When I update my PATH using either the built-in Environment Variables dialog, or something like Path Editor, and then open up a command-prompt, the changes to my PATH will not register with the console, depending on where the command-prompt was started from.

For example, if I edit my PATH and then start cmd.exe from the Start Menu or a shortcut on the Desktop, then my PATH looks fine: it has successfully been updated; however, if I start cmd.exe from a shortcut anywhere other than the Start Menu or Desktop, the new PATH does not get read and I get the old path instead. It's very strange.

I've tried running the command prompt from a shortcut on the desktop and it works fine; I then copy that exact same shortcut to a sub-folder on the desktop, and I get the non-updating PATH problem.

I realise this is quite hard to explain, so I created a screencast to show this issue in action.

Here's a screenshot of the Command Prompt shortcut as seen in that screencast:

Command prompt shortcut settings

This is on Windows Vista Home Premium SP2.

Charles Roper

Posted 2010-02-11T12:45:24.017

Reputation: 9 646

Answers

29

As Rowland suggests, when starting a new process, it will read the environment variables from the process that is starting it. Therefore, when starting a command-prompt from the Start Menu or the Desktop, it reads the environment variables from explorer.exe which, as grawity suggests, detects changes to environment settings in the registry and thus I see my new PATH in command-prompts started from the Desktop or Start Menu.

The reason I do not see updates to my PATH in the screencast I posted is because I had initially launched an explorer window using FARR making FindAndRunRobot.exe the parent process. FARR doesn't automatically detect environment changes and so, child processes spawned from it do not pick up the new PATH. I also had 'Launch folder windows in a separate process' option set in Explorer which means that all explorer.exe windows I opened subsequent to the initial one opened by FARR where also children of FARR.

By turning-off the 'Launch folder windows in a separate process' option, new explorer.exe processes aren't created under FARR, which solves my problem. However, I also launch console windows and other things directly from FARR; these also get the old environment settings. If I restart FARR, then the new environment settings are propagated.

Here's a screenshot of Process Explorer showing processes spawned from FARR. None of these processes receive the new environment settings from the top-level explorer.exe unless I restart FARR:

process explorer

Charles Roper

Posted 2010-02-11T12:45:24.017

Reputation: 9 646

make great sense. – lwpro2 – 2014-11-06T03:16:20.017

3Why was my answer voted down? If there is a flaw in it, let me know and I'll try to fix it. – Charles Roper – 2010-05-14T10:50:01.677

Charles, perhaps because it would have been better to explicitly correct the Q's inaccurate "if I start cmd.exe from a shortcut anywhere other than the Start Menu or Desktop, the new PATH does not get read". – ChrisJJ – 2020-02-02T23:27:41.060

32

When you start a new process (such as a new command line), it will pick up the environment variables from the process that is starting it. When the path is updated, only the process performing the update can know it has changed, and the setting doesn't propagate until you log back on (for per-user settings) or reboot (for system-wide settings)

Rowland Shaw

Posted 2010-02-11T12:45:24.017

Reputation: 3 607

2However, the main explorer process will detect environment changes in Registry (the dialog box belongs to rundll32) and update its own environment automatically. (At least in XP it does so.) This is why changes are visible when starting cmd from a shortcut. – user1686 – 2010-02-11T13:47:50.867

Rowland, this provided me with enough information to troubleshoot exactly why this was happening, although it didn't answer my question entirely. See my own answer for details. Thanks! – Charles Roper – 2010-02-11T13:50:19.537

This was the solution for me! I am using Git Bash for Windows within a multitab wrapper (ConEmu) and wondered why echo $PATH wasn't working. I assumed it would be fresh but didn't come out right until I closed all Git Bash tabs and ConEmu. – Oliv Utilo – 2018-04-05T15:26:44.233

Thanks for this answer! All I had to do was close my command prompt and open it again. – user1477388 – 2014-02-04T17:24:17.140