Advertisement

Create Environment Variable in Windows 10

Environment variables in an operating system are values that contain information about the system environment, and the currently logged in user. They existed in OSes before Windows as well, such as MS-DOS. Applications or services can use the information defined by environment variables to determine various things about the OS, for example, to detect the number of processes, the currently logged in user's name, the folder path to the current user's profile or the temporary files directory. Today, we will review a number of methods you can use to create a new user and system environment variable in Windows 10.

Advertisеment

Windows 10 has several types of environment variables: user variables, system variables, process variables and volatile variables. User environment variables are accessible to all apps which run in the current user context, system environment variables apply to all users and processes on the PC; process variables are applicable only to a specific process and volatile variables are those which exist only for the current logon session. Most interesting of these are user, system and process variables, as we can modify them.

Example: A user environment variable.

Windows 10 User Environment Variable

Example: A system environment variable.

Windows 10 System Environment Variable

Windows 10 stores user environment variables under the following Registry key:

HKEY_CURRENT_USER\Environment

System variables are stored under the following key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Reference: How to see names and values of environment variables in Windows 10

To Create a User Environment Variable in Windows 10,

  1. Open the classic Control Panel.
  2. Navigate to Control Panel\User Accounts\User Accounts.
  3. On the left, click on the Change my environment variables link.Windows 10 Change My Environment Variables Link
  4. In the next dialog, click the New button under the User variables for <username> section.Windows 10 New User Variable
  5. Enter a variable name you want to create, then enter a variable value you want to assign to it. The dialog allows browsing for a file or folder to save your time.Windows 10 New User Variable Dialog
  6. Click the OK button, and you are done.Windows 10 New User Variable Is Set

Note: Re-open the required apps (e.g. Command Prompt) to make them read your new environment variable.

Tip: There are a number of other methods you can use to open the environment variables editor in Windows 10. First of all, you can create a special shortcut to open it directly. See Create Environment Variables Shortcut in Windows 10.

Also, there's a special RunDLL command that you can use (Press Win + R and copy-paste it to the Run box):

rundll32.exe sysdm.cpl,EditEnvironmentVariables

Finally, you can right-click the This PC icon in File Explorer and select Properties from the context menu. Click the "Advanced System Settings" link on the left. In the next dialog, "System Properties", you will see the Environment Variables... button in the bottom of the Advanced tab. Moreover, the Advanced System Settings dialog can be directly opened with the systempropertiesadvanced command entered into the Run dialog.

Create a User Environment Variable in Command Prompt

  1. Open a new command prompt
  2. Type the following command: setx <variable_name> "<variable_value>"
  3. Substitute <variable_name> with the actual name of the variable you want to create.
  4. Substitute "<variable_value>" with the value you want to assign to your variable.Windows 10 New User Variable Command Prompt 1

Do not forget to restart your apps (e.g. Command Prompt) to make them read your new environment variable.

Windows 10 New User Variable Command Prompt 2

The setx command is a console tool that can be used to set or unset user and system environment variables. In the general case, the syntax is as follows:

setx variable_name variable_value - set an environment variable for the current user.

setx /M variable_name  variable_value - set an environment variable for all user (system-wide).

Type setx /? in a command prompt to see more details about this tool.

Create a User Environment Variable in PowerShell

  1. Open PowerShell.
  2. Type the following command:
    [Environment]::SetEnvironmentVariable("<variable_name>", "<variable_value>" ,"User")
  3. Substitute <variable_name> with the actual name of the variable you want to create.
  4. Substitute "<variable_value>" with the value you want to assign to your variable.Windows 10 New User Variable PowerShell

Similarly, you can create a system environment variable.

Create a System Environment Variable

  1. Open the Run dialog (Win + R), and execute the command systempropertiesadvanced .
  2. In the System Properties dialog, switch to the Advanced tab. Click on the Environment Variables... button.Windows 10 New System Environment Variable 1
  3. In the next dialog, click the New button under the System variables section.Windows 10 New System Environment Variable 2
  4. Set the desired name for a variable you want to create, and specify its value, then click OK.Windows 10 New System Environment Variable 3

Create a User Environment Variable in Command Prompt

  1. Open a new command prompt as Administrator.
  2. Type the following command: setx /M <variable_name> "<variable_value>"
  3. Substitute <variable_name> with the actual name of the variable you want to create.
  4. Substitute "<variable_value>" with the value you want to assign to your variable.Windows 10 Cmd New System Environment Vairable

The /M switch makes the setx command create a system variable.

Create a System Environment Variable in PowerShell

  1. Open PowerShell as Administrator. Tip: You can add "Open PowerShell As Administrator" context menu.
  2. Type the following command:
    [Environment]::SetEnvironmentVariable("<variable_name>", "<variable_value>" ,"Machine")
  3. Substitute <variable_name> with the actual name of the variable you want to create.
  4. Substitute "<variable_value>" with the value you want to assign to your variable.Windows 10 PowerShell New System Environment Vairable

The last parameter of the SetEnvironmentVariable call tells it to register the given variable as a system variable.

That's it.

Related articles:

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

2 thoughts on “Create Environment Variable in Windows 10”

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.