What is the difference between
SETX
andSET
?As per my understanding:
Both are used to set environment variables
SETX
is for user variables.
SET
is for shell variables.
Solution:
I’m afraid it’s not quite that simple. Environment variables are not limited by scope, as you suggest, but you are right that the lifetime of the value in the variable is different when comparing the verbs.
set
modifies the current shell’s (the window’s) environment values, and the change is available immediately, but it is temporary. The change will not affect other shells that are running, and as soon as you close the shell, the new value is lost until such time as you run set again.
setx
modifies the value permanently, which affects all future shells, but does not modify the environment of the shells already running. You have to exit the shell and reopen it before the change will be available, but the value will remain modified until you change it again.
See here for an example: http://batcheero.blogspot.com/2008/02/set-and-setx.html