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 valor

    Creates or changes the user's environment variable.

  • /M

    Saves the variable for the whole system, not just the user; requires administrator.

  • /S equipo

    Acts on a remote computer.

  • /U usuario

    User to connect to the remote computer as.

  • /K clave

    Takes the value from a registry key instead of typing it.

Usage examples

  • setx MIVAR valor

    Defines the MIVAR variable permanently for your user.

  • setx PROYECTOS C:\Proyectos /M

    Defines 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.

Related commands