System Create New Environment Variables in Windows 11


  • Staff
Environment_Variables_banner.png

This tutorial will show you how to set (create) new user and system environment variables in Windows 10 and Windows 11.

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%" for command and "$Env:UserProfile" for PowerShell) 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 (machine) environment variables (set for all users).

User environment variables are stored in the registry key below:

HKEY_CURRENT_USER\Environment

System environment variables are stored in the registry key below:

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

You can open a command prompt, type set, and press Enter to display all current environment variables on your PC.

You can open PowerShell, type Get-ChildItem Env:, and press Enter to display all current environment variables on your PC.



Contents

  • Option One: Create New User Environment Variables in Environment Variables
  • Option Two: Create New User Environment Variables using "setx" Command
  • Option Three: Create New User Environment Variables in PowerShell
  • Option Four: Create New System Environment Variables in Environment Variables
  • Option Five: Create New System Environment Variables using "setx" Command
  • Option Six: Create New System Environment Variables in PowerShell




Option One

Create New User Environment Variables in Environment Variables


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)

This opens rundll32.exe sysdm.cpl,EditEnvironmentVariables.


Add_user_environmental_variables-1.png

3 Click/tap on the New button under the top User variables for <current user name> section. (see screenshot below)

Add_user_environmental_variables-2.png

4 Perform the steps below: (see screenshot below)
  1. Enter a Variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
  2. Enter a Variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.
  3. Click/tap on OK.

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.


Add_user_environmental_variables-3.png

5 When finished creating new user variables for your account, click/tap on OK to apply (set) the new variables. (see screenshot below)

Add_user_environmental_variables-4.png




Option Two

Create New User Environment Variables using "setx" Command


1 Open Windows Terminal, and select either Windows PowerShell or Command Prompt.

2 Type the command below into Windows Terminal, and press Enter. (see screenshot below)

setx [variable name] "[variable value]"

Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").

Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.

For example: setx Downloads "C:\Users\Brink\Downloads"


3 You can now close Windows Terminal if you like.

Add_user_environmental_variables-command.png





Option Three

Create New User Environment Variables in PowerShell


1 Open Windows Terminal, and select Windows PowerShell.

2 Type the command below into Windows Terminal, and press Enter. (see screenshot below)

[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","User")

Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").

Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable.

For example: [Environment]::SetEnvironmentVariable("Downloads","C:\Users\Brink\Downloads","User")


3 You can now close Windows Terminal if you like.

Add_user_environmental_variables-PowerShell.png





Option Four

Create New System Environment Variables in Environment Variables


You must be signed in as an administrator to use this option


1 Open Advanced System Properties (SystemPropertiesAdvanced.exe).

2 Click/tap on the Environment Variables button. (see screenshot below)

Add_system_environmental_variables-1.png

3 Click/tap on the New button under the bottom System variables section. (see screenshot below)

Add_system_environmental_variables-2.png

4 Perform the steps below: (see screenshot below)
  1. Enter a Variable name {ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").
  2. Enter a Variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.
  3. Click/tap on OK.

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.


Add_system_environmental_variables-3.png

5 When finished creating new system variables, click/tap on OK to apply (set) the new variables. (see screenshot below)

Add_system_environmental_variables-4.png

6 Click/tap on OK. (see screenshot below)

Add_system_environmental_variables-5.png




Option Five

Create New System Environment Variables using "setx" Command


You must be signed in as an administrator to use this option


1 Open Windows Terminal (Admin), and select Windows PowerShell.

2 Type the command below into Windows Terminal (Admin), and press Enter. (see screenshot below)

setx [variable name] "[variable value]" /m

Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").

Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.

For example: setx Downloads "%UserProfile%\Downloads" /m


3 You can now close Windows Terminal (Admin) if you like.

Add_system_environmental_variables-command.png





Option Six

Create New System Environment Variables in PowerShell


You must be signed in as an administrator to use this option


1 Open Windows Terminal (Admin), and select Windows PowerShell.

2 Type the command below into Windows Terminal (Admin), and press Enter. (see screenshot below)

[Environment]::SetEnvironmentVariable("[variable name]","[variable value]","Machine")

Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads").

Substitute [variable value] in the command above with the actual variable value (ex: "%UserProfile%\Downloads") you want referenced by the environment variable.

For example: [Environment]::SetEnvironmentVariable("Downloads","%UserProfile%\Downloads","Machine")


3 You can now close Windows Terminal (Admin) if you like.

Add_system_environmental_variables-PowerShell.png



That's it,
Shawn Brink


 

Attachments

  • Environment_Variables.png
    Environment_Variables.png
    1.6 KB · Views: 7
Last edited:
Hi,
Man I can't believe you showed where a onedrive folder is
Now I'm supposed to leave it there right :zany:
 

My Computer

System One

  • OS
    Win-7-10-11Pro's
    Computer type
    PC/Desktop
    Manufacturer/Model
    Acer 17" Nitro 7840sn/ 2x16gb 5600c40/ 4060/ stock 1tb-os/ 4tb sn850x
    CPU
    10900k & 9940x & 5930k
    Motherboard
    z490-Apex & x299-Apex & x99-Sabertooth
    Memory
    Trident-Z Royal 4000c16 2x16gb & Trident-Z 3600c16 4x8gb & 3200c14 4x8gb
    Graphics Card(s)
    Titan Xp & 1080ti FTW3 & evga 980ti gaming
    Sound Card
    Onboard Realtek x3
    Monitor(s) Displays
    1-AOC G2460PG 24"G-Sync 144Hz/ 2nd 1-ASUS VG248QE 24"/ 3rd LG 43" series
    Screen Resolution
    1920-1080 not sure what the t.v is besides 43" class scales from 1920-1080 perfectly
    Hard Drives
    2-WD-sn850x 4tb/ 970evo+500gb/ 980 pro 2tb.
    PSU
    1000p2 & 1200p2 & 850p2
    Case
    D450 x2 & 1 Test bench in cherry Entertainment center
    Cooling
    Custom water loops x3 with 2x mora 360mm rads only 980ti gaming air cooled
    Keyboard
    G710+x3
    Mouse
    Redragon x3
    Internet Speed
    xfinity gigabyte
    Browser
    Firefox
    Antivirus
    mbam pro
Oh great. It's not like people have enough problems with just the existing Environment Variables.
Now... we will have custom ones to deal with too. :D
 

My Computers

System One System Two

  • OS
    Win 11 Home ♦♦♦22631.3527 ♦♦♦♦♦♦♦23H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® [May 2020]
    CPU
    AMD Ryzen 7 3700X
    Motherboard
    Asus Pro WS X570-ACE (BIOS 4702)
    Memory
    G.Skill (F4-3200C14D-16GTZKW)
    Graphics Card(s)
    EVGA RTX 2070 (08G-P4-2171-KR)
    Sound Card
    Realtek ALC1220P / ALC S1220A
    Monitor(s) Displays
    Dell U3011 30"
    Screen Resolution
    2560 x 1600
    Hard Drives
    2x Samsung 860 EVO 500GB,
    WD 4TB Black FZBX - SATA III,
    WD 8TB Black FZBX - SATA III,
    DRW-24B1ST CD/DVD Burner
    PSU
    PC Power & Cooling 750W Quad EPS12V
    Case
    Cooler Master ATCS 840 Tower
    Cooling
    CM Hyper 212 EVO (push/pull)
    Keyboard
    Ducky DK9008 Shine II Blue LED
    Mouse
    Logitech Optical M-100
    Internet Speed
    300/300
    Browser
    Firefox (latest)
    Antivirus
    Bitdefender Internet Security
    Other Info
    Speakers: Klipsch Pro Media 2.1
  • Operating System
    Windows XP Pro 32bit w/SP3
    Computer type
    PC/Desktop
    Manufacturer/Model
    Built by Ghot® (not in use)
    CPU
    AMD Athlon 64 X2 5000+ (OC'd @ 3.2Ghz)
    Motherboard
    ASUS M2N32-SLI Deluxe Wireless Edition
    Memory
    TWIN2X2048-6400C4DHX (2 x 1GB, DDR2 800)
    Graphics card(s)
    EVGA 256-P2-N758-TR GeForce 8600GT SSC
    Sound Card
    Onboard
    Monitor(s) Displays
    ViewSonic G90FB Black 19" Professional (CRT)
    Screen Resolution
    up to 2048 x 1536
    Hard Drives
    WD 36GB 10,000rpm Raptor SATA
    Seagate 80GB 7200rpm SATA
    Lite-On LTR-52246S CD/RW
    Lite-On LH-18A1P CD/DVD Burner
    PSU
    PC Power & Cooling Silencer 750 Quad EPS12V
    Case
    Generic Beige case, 80mm fans
    Cooling
    ZALMAN 9500A 92mm CPU Cooler
    Mouse
    Logitech Optical M-BT96a
    Keyboard
    Logitech Classic Keybooard 200
    Internet Speed
    300/300
    Browser
    Firefox 3.x ??
    Antivirus
    Symantec (Norton)
    Other Info
    Still assembled, still runs. Haven't turned it on for 13 years?

Latest Support Threads

Back
Top Bottom