setx
Windows CMD · Terminal · reference only
What it does
Creates or modifies environment variables permanently, for the user or the whole system.
Syntax
setx nombre valor [/M]
Options and parameters
nombre valorCreates or changes the user's environment variable.
/MSaves the variable for the whole system, not just the user; requires administrator.
/S equipoActs on a remote computer.
/U usuarioUser to connect to the remote computer as.
/K claveTakes the value from a registry key instead of typing it.
Usage examples
setx MIVAR valorDefines the MIVAR variable permanently for your user.
setx PROYECTOS C:\Proyectos /MDefines a variable for the whole system.
setx PATH "%PATH%;C:\Herramientas"Adds a folder to PATH, with the limitation mentioned in the notes.
echo %MIVAR%In a new console it shows the value; in the current one it does not exist yet.
Notes and common mistakes
- The change is only seen in consoles you open afterwards, not in the current one.
- setx truncates the value to 1024 characters: with a long PATH it can damage it; use the environment variables window.