Home NT Commands
NT Syntax

SETX.exe (Resource Kit)

Set environment variables permanently

SETX writes variables to the master environment in the registry. Changes made using SETX are only available in future command windows and not in the current command window.
Two types of variable can be set - a permanent user variable (HKCU) or a permanent machine variable (HKLM) Admin rights are required for the latter.

SETX can be used in 3 modes:

1) Set Environment Variables for the machine or currently logged on user:

     SETX variable value [-m] 
-m Sets value in the Machine environment. Default is User.

2) Registry Mode: see the newer REG command for this

3) File Mode: Edit CR-LF text files, (like win.ini) for more information use: SETX -i

Examples:

SETX v_machine COMPAQ
Sets value of v_machine to be COMPAQ in the users environment.
this is the same as the command SET v_machine=COMPAQ

SETX v_machine "COMPAQ COMPUTER" -m
Sets value of v_machine to be "COMPAQ COMPUTER" in the machine environment.

SETX v_mypath %PATH%
Sets the value of v_mypath to the CURRENT value of the PATH environment variable.

SETX v_mypath ~PATH~
Sets the value of v_mypath to ALWAYS be equal to the value of the PATH environment variable even in the event that the PATH variable changes.

Registry Size
This can be increased in the control panel or from
HKLM\SYSTEM\CurrentControlSet\Control\RegistrySizeLimit

"You are never dedicated to something you have complete confidence in. No-one is fanatically shouting that the sun is going to rise tomorrow. When people are fanatically devoted to political or religious faiths or any other kind of dogmas or goals, its always because these dogmas or goals are in doubt" - Robert T Pirsig

Related Commands:

SET - Display, set, or remove Windows NT environment variables
Q104011 - Modify variables by editing the Registry
SETENV - Vincent Fatica's improved version

Equivalent Linux BASH commands:

env - Display, set, or remove environment variables
export - Set an environment variable



Simon Sheppard
SS64.com