Can I change the PATH environmental variable in Windows 7 without restarting?

22

2

Is there anyway to change the PATH environment variable (or variables in general) on Windows 7 Exterprise (64 bit) and have it take effect in PowerShell or the command prompt (cmd.exe) without requiring a restart?

I don't mind having the reopen the shell/prompt, but having to restart is too much.

I'm currently changing variables through Advanced Systems settings ->Environment Variables`.

Danielb

Posted 2009-11-28T01:16:52.683

Reputation: 619

MS outline the issue with anything relying on services running under the local system account, but that should only affect PSExec sessions. Also, many client programs using environment variables may not require reboot or user logout/login, so long as they are restarted after the EV change. (verified with VS2017)

– Laurie Stearn – 2018-01-11T05:02:32.923

Answers

22

The requirement really isn't "must restart", it's "must log out/log back in" -- mostly for your current user processes to pick up the change.

If all you're interested in is for the variable changes to take effect in a command window or power shell, starting a new shell after making said changes should be all that's needed.

quack quixote

Posted 2009-11-28T01:16:52.683

Reputation: 37 382

Make sure you restart the process creating cmd after changing the system environment variables. Killing explorer often does the trick. – masterxilo – 2016-02-21T18:31:46.123

Also programs (in my case NUnit) will often read the new path changes if you open and close them. – Matthew Lock – 2012-04-02T23:53:51.457

11Its weird creating a new terminal/shell window after making changes always used to work on previous windows versions but it doesn't seem to be enough on Win7 :( – Danielb – 2009-11-29T19:27:34.253

1If use "Open Command Window Here" in explorer I can see the new path with echo %PATH% but not if I just run cmd.exe – Glenn Lawrence – 2014-03-18T06:06:52.697

1@GlennLawrence for me it's the opposite: I see my changes if I invoke cmd from the Start menu (either by searching for it or by using the Run… function). If I invoke it from a batch file or from the context menu, I do not see my changes. – Saulo Silva – 2014-03-31T19:41:44.607

3

In my Win7 (64-bit) the console command

path=drive:\dir;%path%

adds drive:\dir to the beginning of the current console's path without starting a new console. No idea why your Win7 should behave differently. I'd like to know how some programs add themselves to the %path% variable for every instance of the console, though.

To change the Windows 7 path manually, check: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

TJGeezer

Posted 2009-11-28T01:16:52.683

Reputation: 31

2

I solved this problem by choosing Command Prompt or Windows PowerShell from the start menu, right clicking and choosing "Run as administrator". Then the new command window will recognize the changes to PATH, otherwise it does not. I don't know what will happen after a restart.

Rob

Posted 2009-11-28T01:16:52.683

Reputation: 21

Fine, but is there a difference if the account is already an admin? – Laurie Stearn – 2018-01-11T04:32:53.557