I have to set environment variables on different windows machines, but I don’t want to be bothered changing them manually by getting on the properties screen of "My Computer"
I want to do it from the command line, with a batch file. As far as I understand, using set will only change the variable for the processes I will call in the command window.
I want to set it definitely, so later, when running a new process, it will use those new settings I have set. Is there a way to do that from the command line?
Use the SETX command (note the ‘x’ suffix) to set variables that persist after the cmd window has been closed.
For example, to set an env var "foo" with value of "bar":
Though it’s worth reading the ‘notes’ that are displayed if you print the usage (
setx /?), in particular:In PowerShell, the [Environment]::SetEnvironmentVariable command.