Windows Environment Variable Tutorial

By Xah Lee. Date: . Last updated: .

What is Environment Variable

Environment variables are system-wide global variables. They are 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.

Windows environment variable names are not case sensitive

View Environment Variables

Press ❖ Window key, then type “environment”

or

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

Windows 10 SystemPropertiesAdvanced 2021-02-04
Windows 10 SystemPropertiesAdvanced 2021-02-04

Sample Values of Environment Variable

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

Types of Environment Variable

There are 3 types of environment variable:

Process
Per session. It is temporary. It exist only for the current session in cmd.exe or PowerShell. After you exit the shell, the variables you created are gone. When a shell starts, it gets environment variable from the Windows Registry.
User
Permanent, stored in Windows Registry. Per user. Each user may have different values.
Examples: home folder HOMEPATH, temp dir (TEMP and or TMP).
In Registry, they are at: HKEY_CURRENT_USER\Environment.
Machine
Permanent, stored in Windows Registry. Per machine. Each machine may have different values.
Examples:
  • OS kernal path (WINDIR)
  • processor info (PROCESSOR_ARCHITECTURE, NUMBER_OF_PROCESSORS, etc)
  • application paths (PATH)
  • executable file name extensions (PATHEXT)
  • OS type (OS)
  • current user name (USERNAME)

In Registry, they are at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
[see Windows: Registry Tutorial]

Process environment variable is also known as Local Environment Variable.

User environment variable and Machine environment variable are together also known as System Environment Variable.

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.

Show / Set Environment Variables using Powershell

Show / Set Environment Variables using cmd.exe