You may want to make these two permanent with setx but obviously no need to C:\>set uvar=HKCU\Environment C:\> C:\>set mvar=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment C:\>
Some terminology
Inside the key (which looks like a folder) you have a variable with some data like a = 5
http://msdn.microsoft.com/en-us/library/3dwk5axy.aspx talks about name (a), meaning (5).
Registry terminology is slightly different from msdn, but reg.exe and wikipedia seem consistent. wikipedia http://en.wikipedia.org/wiki/Windows_Registry says that "Registry values ββare name / data pairs stored in keys" refers to a name / data pair. name (a) of data (5), and a pair together is a value.
The REG seems to use / v, which probably refers to both the name of the variable and its data (as in wikipedia), it shows both the name of the variable and its data. And REG has a / d, which I suppose is for data only.
Setx example
C:\>reg query %uvar% HKEY_CURRENT_USER\Environment TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp ... C:\>setx aaa 3 C:\>reg query %uvar% HKEY_CURRENT_USER\Environment TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp ... aaa REG_SZ 3
If you try to use setx to delete it, the closest you can get cleans it like this article. MS KB this article MS50 195050 says that it leaves you with it in the registry.
setx does not remove a variable from the registry
C:\>setx aaa "" SUCCESS: Specified value was saved. C:\>reg query %uvar% HKEY_CURRENT_USER\Environment TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp ... aaa REG_SZ C:\>
However, it is worth noting that the variable left before the cmd prompt. echo% aaa% will display% aaa% so the variable disappears. Currently, there is only unnecessary garbage in the registry.
User
makes an interesting point that now when you try to set a system variable, it does not work. since it will be overwritten by what is in the user variable, in this case it will always be displayed as undefined.
C:\>reg delete %uvar% /v aaa Delete the registry value aaa (Yes/No)? y The operation completed successfully. C:\>
Note that aaa is now gone. Below.
C:\>reg query %uvar% HKEY_CURRENT_USER\Environment TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp ... C:\>
If you want to do this for the system / machine environment variable, not for the user.
- the lines below should be called by the administrative privileged call to cmd
-key number: HKLM \ SYSTEM \ CurrentControlSet \ Control \ Session Manager \ Environment
-% Mvar% (unlike% uvar%) needs quotes around it, because the key has a space. If you miss the quotes, it will not be difficult for you, you will get an error that may remind you to use quotation marks.
-And of course, if you want to set the environment variable in this part of the registry using setx, use, for example, setx aaa 5 -m, i.e. -m after.
C:\>set mvar=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment C:\>reg delete "%mvar%" /v aaa Delete the registry value aaa (Yes/No)? y The operation completed successfully. C:\>
further note
Perhaps you can only create an environment variable using REG ADD or REG DELETE .. (instead of setx), but in any case, when setting a variable, you can also use set set so that it is also set for the current session and not just the next . And the link is re setx https://superuser.com/questions/647505/set-enviroment-variable-setx