Windows command line update environment variables




















Your change won't be visible in the current cmd. Dealing with the Path variable is sticky as it is a combination of the system Path and user Path variables. The previous answers don't account for this. For example. Unfortunately, dealing with the Path variables is a pain as it involves updating registry and to be able to append a new value we must first copy the registry entry into an environment variable, append directory that we are adding to the path, and then write the results back into the registry.

This means whatever mechanism you use for reading, manipulating, and then writing the Path variable should ideally not expand anything. Finally, it's common for there to be no user Path variable meaning the code that updates the Path needs to account for the error you will get if you try to read a variable that does not exist.

If you want to set a path or other environment variable with spaces in it, I found it easier to use regedit - which you can just start from the command prompt on Server Core.

Based on that, adapting the code from that answer if you need code or just using regedit if you just want to make a few changes by hand might be safer Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? If your spelling is not wrong and the computer has that program installed, then the error is caused because your path variable is not set up correctly i.

That simply means that the operating system do not know where to find your mention program. Also read: Merge video clips into one video file using CMD, without any software.

Here you will see all the system variables defined on your PC. Now to set the new variable click on New under System variables and give the name of the variable and value is the path of the variable. The original question is how to refresh an environment variable to a value that has been set outisde of that terminal. Although this doesn't answer the question, it provides half of the best working solution. I use this - for whatever variable I am setting - then I open up the control panel and add the environmental variable globally.

I don't like using setx because it inherits the current environment which may have variables that have been modified and not what I want permanently.

Doing it this way allows me to avoid restarting the console in order to use the variables, while avoiding the problem of not having them available globally in the future. Use "setx" and restart cmd prompt There is a command line tool named " setx " for this job.

This allows applications, such as the shell, to pick up your updates. Jens A. Koch Jens A. Koch Could you expand on how to use setx to read an environment variable? I've been over the various documentation and I'm just not seeing it. Buyer beware! And just like that, his evening vanished — FaCE. Show 7 more comments. Sridhar Ratnakumar Brian Weed Brian Weed 1 1 silver badge 2 2 bronze badges.

No, it also works for non-GUI programs. As for listening programs The best method I came up with was to just do a Registry query. Here is my example.

Christopher Holmes Christopher Holmes 1 1 silver badge 3 3 bronze badges. Paul Roub Richard Woodruff Richard Woodruff 81 1 1 silver badge 1 1 bronze badge. Algonaut Algonaut 4 4 silver badges 6 6 bronze badges. Environment variables are not kept in the registry.

What is kept in the registry is a template , from which programs like Windows Explorer re- construct their environment variables when notified to do so.

Actual environment variables are per-process and are stored in each process' own address space, initially inherited from its parent process and modifiable thereafter at the process' whim. Restarting explorer did this for me, but only for new cmd terminals. The terminal I set the path could see the new Path variable already in Windows 7. Moses Davidowitz 11 11 silver badges 27 27 bronze badges.

Vince Vince 81 1 1 silver badge 1 1 bronze badge. Easiest way. Thank you. Daniel Fensterheim Daniel Fensterheim 1 1 gold badge 3 3 silver badges 8 8 bronze badges. Sebastian Sebastian 3 3 silver badges 10 10 bronze badges.

While I get what you've done, most likely he wants something for parallel scripts, one script sets globals while another reads them. Otherwise, there's no point in involving setx, set would be sufficient. If it concerns just one or a few specific vars you want to change, I think the easiest way is a workaround : just set in in your environment AND in your current console session Set will put the var in your current session SetX will put the var in the environment, but NOT in your current session I have this simple batch script to change my Maven from Java7 to Java8 which are both env.

The best choice, IMO. Charles Grunwald Charles Grunwald 1, 16 16 silver badges 21 21 bronze badges. I like your answer. Post the same answer to my question here stackoverflow. Display this help. REM The option used here is to create a temporary batch file that will define all the variables. REM Check to make sure we don't overwrite an actual file. The script was aborted in order to prevent accidental data loss.

Delete this file to enable this script. When a process starts a childprocess, it's able to adjust the environment for that child. Since it's not part of the actual environment variables, it won't be updated by this script. Hi DieterDP , your solution works for me! I'm using Windows 10 on a bit machine. Nevertheless, the update of the environment variables is successful.

Where does the error come from? Hard to say without actually testing it myself, but I'm guessing the registry structure on W10 may slightly differ. If you feel like it, try hunting the error down by executing the commands on the command line. REM In my case I just had to kill the windows explorer process from the task manager and then restart it again from the task manager.

REM Once I did this I had access to the new environment variable from a cmd that was spawned from windows explorer. REM my conclusion: REM if I add a new variable with setx, i can access it in cmd only if i run cmd as admin, without admin right i have to restart explorer to see that new variable.

Somehow the parser properly finds and loads the running. Hopefully MicroSoft will never disable that "feature". Environment "System" for each sitem in oEnvS tmpF.

Environment "User" for each sitem in oEnvU tmpF. Environment "Volatile" for each sitem in oEnvV tmpF. But string length doesnt mean that you can save characters in a variable because also the assignment belongs to the string.

Dictionary" REM ' force dictionary compare to be case-insensitive , uncomment to force case-sensitive dict. With Windows XP, the reg tool allows for accessing the registry from the command line. We can use this to look at the environment variables.

This will work the same way in the command prompt or in powershell. This technique will also show the unexpanded environment variables, unlike the approaches shown for the command prompt and for powershell. When setting environment variables on the command line, setx should be used because then the environment variables will be propagated appropriately. The reg tool can take care of that, however another setx command should be run afterwards to propagate the environment variables.



0コメント

  • 1000 / 1000