If I modify or add an environment variable I have to restart the command prompt. Is there a command I could execute that would do this without restarting CMD?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can capture the system environment variables with a vbs script, but you need a bat script to actually change the current environment variables, so this is a combined solution.
Create a file named
resetvars.vbscontaining this code, and save it on the path:create another file name resetvars.bat containing this code, same location:
When you want to refresh the environment variables, just run
resetvars.batApologetics:
The two main problems I had coming up with this solution were
a. I couldn’t find a straightforward way to export environment variables from a vbs script back to the command prompt, and
b. the PATH environment variable is a concatenation of the user and the system PATH variables.
I’m not sure what the general rule is for conflicting variables between user and system, so I elected to make user override system, except in the PATH variable which is handled specifically.
I use the weird vbs+bat+temporary bat mechanism to work around the problem of exporting variables from vbs.
Note: this script does not delete variables.
This can probably be improved.
ADDED
If you need to export the environment from one cmd window to another, use this script (let’s call it
exportvars.vbs):Run
exportvars.vbsin the window you want to export from, then switch to the window you want to export to, and type: