Set environment variables permanently
SETX can be used to set Environment Variables for the machine or currently logged on user:
SETX Variable Value
SETX Variable Value -m
-m Set the value in the Machine environment (HKLM)
Default is User (HKCU)
SetX can also be used in modes to edit the Registry or edit CR-LF text files, (like win.ini) for most purposes these tasks are better done with other tools in the resource kit, e.g. the REG command.
Because SetX writes variables to the master environment in the registry. Edits will only take effect when a new command window is opened – they do not affect the current command session.
A value of &qt; (empty quotes) will appear to delete the variable – it&qt;&qt;s not shown by SET but the variable name will remain in the registry. Either use the GUI (recommended) or delete the value from the registry with REG
REG delete HKCUEnvironment /V _myvar
Deleting a variable in this way does not take effect until next logon due to caching of registry data. The type is REG_EXPAND_SZ.
Set the variable "_mypc" to be COMPAQ in the users permanent environment:
SetX _mypc COMPAQ
Delete the variable "_myvar" in the users permanent environment:
REG delete HKCUEnvironment /V _mypc
Set the variable "_myTimeZone" in both the immediate user session and the permanent environment:
SetX _myTimeZone GMT
Store the value of &qt;my_important_var&qt; in a second environment variable.
SetX _mybackupvar &qt;my_important_var&qt;
Sets the value of _mypath to ALWAYS be equal to the value of the &qt;PATH&qt; environment variable even in the event that the PATH variable changes:
SetX _mypath ~PATH~
These are stored on the machine and won&qt;&qt;t follow a users roaming profile.
To set a machine variable (-m) requires Administrator rights.
Create a machine variable:
SetX _myvar COMPAQ -m
Delete a machine variable:
REG delete HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment /V _myvar