How to Set New User and System Environment Variables in Windows
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. The variables can be used both in scripts and on the command line. Environment variables makes it easy when certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.
The variable (ex: "%UserProfile%") is used as a type of shortcut of the value (ex: "C:\Users\<username>").
There are two types of environment variables: user environment variables (set only for current user) and system environment variables (set for all users).
This tutorial will show you how to set (create) new user and system environment variables in Windows 7, Windows 8, and Windows 10.
User environment variables are stored in the
HKEY_CURRENT_USER\Environment
registry key.
System environment variables are stored in theHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
registry key.
Contents
- Option One: Set New User Environment Variables in Environment Variables
- Option Two: Set New User Environment Variables in Command Prompt
- Option Three: Set New User Environment Variables in PowerShell
- Option Four: Set New System Environment Variables in Environment Variables
- Option Five: Set New System Environment Variables in Command Prompt
- Option Six: Set New System Environment Variables in PowerShell
1 Open the Control Panel (icons view), and click/tap on the User Accounts icon.
2 Click/tap on the Change my environment variables link on the left side, and close the User Accounts control panel window if you like. (see screenshot below)
3 Click/tap on the New button under the top User variables for <current user name> section. (see screenshot below)
4 Enter a variable name you want to use, enter a variable value you want to use, and click/tap on OK. (see screenshot below)
If you like, you could click/tap on the Browse Directory button to navigate to and select a directory to have its path entered for the variable value.
If you like, you could click/tap on the Browse File button to navigate to and select a file to have its path entered for the variable value.
5 When finished creating new user variables, click/tap on OK to apply (set) the new variables. (see screenshot below)
1 Open a command prompt.
2 Type the command below into the command prompt, and press Enter. (see screenshot below)3 You can now close the command prompt if you like.
setx [variable name] "[variable value]"
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want to use.
Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want to use.
1 Open Windows PowerShell.
2 Type the command below into PowerShell, and press Enter. (see screenshot below)3 You can now close Windows PowerShell if you like.
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","User")
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want to use.
Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want to use.
You must be signed in as an administrator to do this option.
1 Open the Control Panel (icons view), and click/tap on the System icon.
Starting with Windows 10 build 20161, you will need to open Settings instead, click/tap on the System icon, and click/tap on About on the left side.
2 Click/tap on the Advanced system settings link on the left side, and close the System window if you like. (see screenshots below)
![]()
3 Click/tap on the Environment Variables button. (see screenshot below)
4 Click/tap on the New button under the bottom System variables section. (see screenshot below)
5 Enter a variable name you want to use, enter a variable value you want to use, and click/tap on OK. (see screenshot below)
If you like, you could click/tap on the Browse Directory button to navigate to and select a directory to have its path entered for the variable value.
If you like, you could click/tap on the Browse File button to navigate to and select a file to have its path entered for the variable value.
6 When finished creating new system variables, click/tap on OK to apply (set) the new variables. (see screenshot below)
7 Click/tap on OK. (see screenshot below)
You must be signed in as an administrator to do this option.
1 Open an elevated command prompt.
2 Type the command below into the elevated command prompt, and press Enter. (see screenshot below)3 You can now close the elevated command prompt if you like.
setx [variable name] "[variable value]" -M
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want to use.
Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want to use.
You must be signed in as an administrator to do this option.
1 Open an elevated Windows PowerShell.
2 Type the command below into the elevated PowerShell, and press Enter. (see screenshot below)3 You can now close the elevated Windows PowerShell if you like.
[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","Machine")
Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want to use.
Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want to use.
That's it,
Shawn
Related Tutorials
- Complete List of Environment Variables in Windows 10
- How to Create Environment Variables Shortcut in Windows
- How to Edit User and System Environment Variables in Windows
- How to Delete User and System Environment Variables in Windows
- How to Add Environment Variables Context Menu in Windows 10