Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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)

share|improve this answer
1  
However, 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. –  grawity Feb 11 '10 at 13:47
    
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 Feb 11 '10 at 13:50
    
Thanks for this answer! All I had to do was close my command prompt and open it again. –  user1477388 Feb 4 at 17:24
up vote 6 down vote accepted

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

share|improve this answer
    
Why was my answer voted down? If there is a flaw in it, let me know and I'll try to fix it. –  Charles Roper May 14 '10 at 10:50
    
make great sense. –  lwpro2 Nov 6 at 3:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.