Windows Environment Variables Tutorial

By Xah Lee. Date: . Last updated: .

This page is a basic tutorial on Windows's Environment Variables. The code here is tested on Windows 10.

What's Environment Variables

Environment variables are system-wide global variables. They are somewhat like config parameters, and is used by processes. For example, apps need to know the path of your Windows kernal, path of your home dir, paths to search for shell programs, etc.

Not Case Sensitive

Windows environment variable names are Not Case Sensitive.

View Environment Variables

powershell env var 2017 05 08
PowerShell showing environment variables

In PowerShell, type Get-ChildItem env:

[see Using PowerShell to Manage Environment Variables]

cmdexe environment variable 2017 05 08
cmd.exe showing environment variables, by set

In Command Prompt (cmd.exe), type set

To view via GUI:

windows 10 env var gui 2017 05 08
Windows 10 GUI for environment variable.

Press ❖Window key, then type “environment”


  1. goto Control Panel\System and Security\System
  2. Click the 〖Advanced system settings〗 link on the left pane, then 〖Advanced〗 tab, then the 〖Environment Variables…〗 button.

Or type in shell c:\Windows\System32\SystemPropertiesAdvanced.exe to launch the GUI app directly.

Windows env var
The Windows System control panel for editing env vars.

Sample Values of Environment Variable

Here's example of env var values as it exists on my system.

Name                           Value
----                           -----
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\h3\AppData\Roaming
asl.log                        Destination=file
CLASSPATH                      .;C:\Program Files (x86)\Java\jre6\lib\ext\
CommonProgramFiles             C:\Program Files\Common Files
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files
CommonProgramW6432             C:\Program Files\Common Files
COMPUTERNAME                   H3-HP
ComSpec                        C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK               NO
FPPUILang                      en-US
home                           \Users\h3
HOMEDRIVE                      C:
homepath                       \Users\h3
LOCALAPPDATA                   C:\Users\h3\AppData\Local
LOGONSERVER                    \\H3-HP
OnlineServices                 Online Services
OOBEUILang                     en-US
OS                             Windows_NT
Path                           C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program …
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PCBRAND                        Pavilion
Platform                       HPD
PROCESSOR_IDENTIFIER           AMD64 Family 16 Model 5 Stepping 3, AuthenticAMD
PROCESSOR_LEVEL                16
PROCESSOR_REVISION             0503
ProgramData                    C:\ProgramData
ProgramFiles                   C:\Program Files
ProgramFiles(x86)              C:\Program Files (x86)
ProgramW6432                   C:\Program Files
PSModulePath                   C:\Users\h3\Documents\WindowsPowerShell\Modules;C:\Windows\system32\Win…
PUBLIC                         C:\Users\Public
QTJAVA                         C:\Program Files (x86)\Java\jre6\lib\ext\
SESSIONNAME                    Console
SystemDrive                    C:
SystemRoot                     C:\Windows
TEMP                           C:\Users\h3\AppData\Local\Temp
TERM                           dumb
TESSDATA_PREFIX                C:\Program Files (x86)\Tesseract-OCR\
TMP                            C:\Users\h3\AppData\Local\Temp
USERDOMAIN                     h3-HP
USERNAME                       h3
USERPROFILE                    C:\Users\h3
VBOX_INSTALL_PATH              C:\Program Files\Oracle\VirtualBox\
windir                         C:\Windows
windows_tracing_flags          3
windows_tracing_logfile        C:\BVTBin\Tests\installpackage\csilogfile.log

One of the most important env var is the PATH. Here's a sample value of path as set in my system (with line break added for easy reading):

C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;
c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;
c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;
c:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\;
C:\Program Files (x86)\Windows Live\Shared;
C:\Program Files (x86)\QuickTime\QTSystem\;
C:\Program Files (x86)\Calibre2\;
C:\Program Files (x86)\nodejs\;

Temporary vs Permanent

A environment variable can be Local or System.

Process Environment Variable is Temporary

Only programs that are launched from that particular shell will be aware of the local env var you've set.

System Environment Variable = Permanent (in Windows Registry)

System env vars has 2 categories: {User, Machine}.


The “User” category env vars are things like home dir (HOME), temp dir (TEMP and or TMP).

In Registry, they are at: HKEY_CURRENT_USER\Environment.


The “Machine” category env vars are any other, usually related to your machine or more general info.

Example of “Machine” environment variables:

In Registry, they are at:

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

[see Microsoft Windows Registry Tutorial]

Note that you can set any new env vars in any category. Programs have access to all your env vars, but which ones are meaningful to the program is up to the program.

View or Set Environment Variables using Powershell

See Using PowerShell to Manage Environment Variables

Viewing Environment Variable Using cmd.exe

To show a value of a env var, type echo %env_var_name%. For example, to show the “path” env var, do:

echo %path%

To see all your env vars, type:


To see all env vars starting with “p”, type:

set p

Set Environment Variable for Current Session Using cmd.exe

To set env var for the current session, use set var_name=value. WARNING: make sure there's no space around the equal sign. Example:

set xx=5
echo %xx%
REM prints 5. (REM is a comment syntax, everything after it is ignored.)
REM prepending a path to the “path” env var 
set PATH="C:\Program Files (x86)\ErgoEmacs;%PATH%"

Set Environment Variable Permanently in Registry

To set env var permanently, use “setx” command. The “setx” command is part of “cmd.exe” in Windows Vista. Here's a example:

REM example of setting HOME env var
setx HOME "C:\Users\mary"
REM example of adding a path
setx PATH "C:\Program Files (x86)\ErgoEmacs;%PATH%"

For detail, type setx /?.

Note: when you set a env var using “setx”, it is set in the registry, however, they are not known in the current session. Restart the “cmd.exe” if you want them to be available.

If you have a question, put $5 at patreon and message me.