Windows Command – setx

Setx creates or modifies environment variables in the user or system environment, without requiring programming or scripting.

The Setx command also retrieves the values of registry keys and writes them to text files.

Setting Environment Variables

Set environment variables permanently, Setx can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).

> setx <variable> <value> [/m]
  • <variable> – Identifies the variable to be set, e.g. JAVA_HOME , PATH etc.
  • <value> – The variable value, e.g. TEMP C:WindowsTemp
  • /m – (Optional) Used to indicate that it is a System variable.

Clearing Environment Variables

To clear an environment variable using Setx.exe at a command prompt:

Click Start, point to Programs, and then click Command Prompt.
To clear a user environment variable, type the following line

> setx <variable> ""

where <variable> is the user environment variable.
To clear a system environment variable, type the following line

> setx <variable> "" -m

where <variable> is the system environment variable.

Close the command prompt.

Using Setx.exe to clear an environment variable value does not affect the variable name.


By Jason Tolotta

Self-proclaimed information technology enthusiast.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.