Windows environment variable default

Windows Environment Variables Tutorial

What’s Environment Variables

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”

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

Windows 10 SystemPropertiesAdvanced 2021-02-04

Sample Values of Environment Variable

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

One of the most important environment variable is PATH . Here’s a sample value of path (with line break added for easy reading):

value of the environment variable PATH

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 Microsoft 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.

What are the default environment variables in Windows?

In Microsoft Windows, environment variables contain configuration values for the entire system, and the current user. In this page, you’ll find the default names and values of the environment variables used by Windows XP, Vista, 7, 8, and 10.

%ALLUSERSPROFILE%

The full path of the All Users profile directory, which contains default profile information shared by every user.

Defaults
Windows XP: C:\Documents and Settings\All Users
Vista/7/8/10: C:\ProgramData

%APPDATA%

Location of AppData hidden folder, used by some installed programs to store user application data.

Defaults
Windows XP: C:\Documents and Settings\UserName\Application Data
Vista/7/8/10: C:\Users\UserName\AppData\Roaming

%CommonProgramFiles%

Location of the Common Files directory. This folder contains files for common programs and utilities on a computer, mostly system and services related.

Defaults
Windows XP/Vista/7/8/10: C:\Program Files\Common Files

%CommonProgramFiles(x86)%

Location of the Common Files directory used by 32-bit programs. Only used in 64-bit versions of Windows.

Defaults
Windows XP/Vista/7/8/10: C:\Program Files (x86)\Common Files

%CommonProgramW6432%

Only used in 64-bit versions of Windows.

Defaults
Windows Vista/7/8/10: C:\Program Files\Common Files

%COMPUTERNAME%

The name of your computer, as set in Control PanelSystemComputer Name.

Defaults
Windows XP/Vista/7/8/10: ComputerName

%ComSpec%

Location of the default command interpreter.

Defaults
Windows XP/Vista/7/8/10: C:\Windows\System32\cmd.exe

%HOMEDRIVE%

The drive letter assigned to the volume which contains your user profiles.

Defaults
Windows XP/Vista/7/8/10: C:
Читайте также:  Как задать размер окна windows

%HOMEPATH%

The path, minus the drive letter, of the current user’s profile directory.

The %local% environment variable points to where the security policies & rules are located for the user’s account. This environment variable is native to Windows 7.

Defaults
Windows XP: \Documents and Settings\UserName
Vista/7/8/10: \Users\UserName

%LOCALAPPDATA%

Location of the Local subfolder of AppData, used by some installed programs to store user data. Common temporary files to be stored here are desktop themes, Windows error reporting, program caching and Internet browser profiles.

Defaults
Windows Vista/7/8/10: C:\Users\UserName\AppData\Local

%LOGONSERVER%

The network location of the logon server. In corporate settings, DomainLogonServer is a Windows logon server on the corporate network domain. For regular users, DomainLogonServer is %COMPUTERNAME%.

Defaults
Windows XP/Vista/7/8/10: \\DomainLogonServer

List of paths, delimited by a semicolon, to be automatically searched for files. Specifically, files with an extension listed in %PATHEXT% are looked for in %PATH% if they are not found in the current directory. Paths are searched in the order listed.

Defaults
Windows XP/Vista/7/8/10: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;[AdditionalPaths]

%PATHEXT%

Files with these extensions, if not found in the current directory, are looked for in %PATH%.

Defaults
Windows XP: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.WSF;.WSH
Vista/7/8/10: .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc

%ProgramData%

Location of the ProgramData hidden folder, used by some installed programs to store user data.

Defaults
Windows Vista/7/8/10: %SystemDrive%\ProgramData

%ProgramFiles%

Location of the Program Files directory, the default location of installed programs. On 64-bit versions of Windows, this directory is the default location of 64-bit programs.

Defaults
Windows XP/Vista/7/8/10: %SystemDrive%\Program Files

%ProgramFiles(x86)%

The default location of 32-bit programs. This variable is only present in 64-bit versions of Windows.

Defaults
Windows XP/Vista/7/8/10: %SystemDrive%\Program Files (x86)

%ProgramW6432%

This variable is used by the WOW64 emulation layer, and is only present in 64-bit versions of Windows.

Defaults
Windows Vista/7/8/10: %SystemDrive%\Program Files

%PROMPT%

A string of special codes that define the current command prompt. Here, $P represents the current drive and directory, and $G represents the greater-than symbol. (For more information, see the PROMPT command.)

Defaults
Windows XP/Vista/7/8/10: $P$G

%PSModulePath%

Location of modules used by Windows PowerShell.

Defaults
Windows Vista/7/8/10: %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\

%PUBLIC%

Location of the Public user profile.

Defaults
Windows Vista/7/8/10: %SystemDrive%\Users\Public

%SystemDrive%

The drive letter of the volume where Windows is installed.

Defaults
Windows XP/Vista/7/8/10: C:

%SystemRoot%

The directory containing the Windows system.

Defaults
Windows XP: C:\Windows or, in older systems, C:\WINNT
Vista/7/8/10: %SystemDrive%\Windows

%TEMP%
%TMP%

The default location of temporary files. The files located in this directory can be deleted periodically to help improve computer performance.

Defaults
Windows XP: %SystemDrive%\Documents and Settings\UserName\Local Settings\Temp
Vista/7/8/10: %SystemRoot%\TEMP (for system processes)
%USERPROFILE%\AppData\Local\Temp (for user processes)

%USERDOMAIN%

The domain of where the current user belongs.

Defaults
Windows XP/Vista/7/8/10: UserDomain

%USERNAME%

The name of the current user.

Defaults
Windows XP/Vista/7/8/10: UserName

%USERPROFILE%

The path to the current user’s profile directory where the current logged in user’s profile data is stored. It’s in this directory that a user can find the following folders: My Documents, My Music, My Pictures, Desktop, and Favorites (Internet Explorer bookmarks).

Defaults
Windows XP: %SystemDrive%\Documents and Settings\UserName
Vista/7/8/10: %SystemDrive%\Users\UserName
  • How to open your user profile folder in Windows.

%windir%

A modern equivalent of/replacement for %SystemRoot%. This directory is where Windows will install. The default directory path for most versions of Windows is c:\Windows (for Windows NT 4 and 2000, it is c:\WinNT).

How-to: Windows Environment Variables

Environment variables are mainly used within batch files, they can be created, modified and deleted for a session using the SET command. To make permanent changes, use SETX

Variables can be displayed using either SET or ECHO.

Variables have a percent sign on both sides: %ThisIsAVariable%
The variable name can include spaces, punctuation and mixed case: %_Another Ex.ample%
(This is unlike Parameter variables which only have one % sign and are always one character long: %A )

Читайте также:  Как удалить папку old удалить windows 10 не удаляется

A variable name may include any of the following characters:
A-Z, a-z, 0-9, # $ ‘ ( ) * + , — . ? @ [ ] _ `

The first character of the name must not be numeric.

Array variables

Unlike PowerShell, which fully supports arrays, there is no built in support for array variables within the CMD shell. However with some effort you can replicate this functionality using a series of separate variables, named to represent the array:

Set elem[1]=First element
Set elem[2]=Second one
Set elem[3]=The third one

To perform array indexing operations with these, use EnableDelayedExpansion and a reference like !elem[%var%]!
this is explained fully in this StackOverflow Q/A.

Standard (built-in) Environment Variables

Variable Volatile
(Read-Only)
Default value assuming the system drive is C:
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\ \AppData\Roaming
CD Y The current directory (string).
ClientName Y Terminal servers only — the ComputerName of a remote host.
CMDEXTVERSION Y The current Command Processor Extensions version number. (NT = «1», Win2000+ = «2».)
CMDCMDLINE Y The original command line that invoked the Command Processor.
CommonProgramFiles C:\Program Files\Common Files
COMMONPROGRAMFILES(x86) C:\Program Files (x86)\Common Files
COMPUTERNAME
COMSPEC C:\Windows\System32\cmd.exe or if running a 32 bit WOW — C:\Windows\SysWOW64\cmd.exe
DATE Y The current date using same region specific format as DATE.
ERRORLEVEL Y The current ERRORLEVEL value, automatically set when a program exits.
FPS_BROWSER_APP_PROFILE_STRING
FPS_BROWSER_USER_PROFILE_STRING
Internet Explorer
Default
These are undocumented variables for the Edge browser in Windows 10. HighestNumaNodeNumber Y (hidden) The highest NUMA node number on this computer. HOMEDRIVE Y C: HOMEPATH Y \Users\ LOCALAPPDATA C:\Users\ \AppData\Local LOGONSERVER \\ NUMBER_OF_PROCESSORS Y The Number of processors running on the machine. OS Y Operating system on the user’s workstation. PATH User and
System C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem; PATHEXT .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH; .MSC
Determine the default executable file extensions to search for and use, and in which order, left to right.
The syntax is like the PATH variable — semicolon separators. PROCESSOR_ARCHITECTURE Y AMD64/IA64/x86 This doesn’t tell you the architecture of the processor but only of the current process, so it returns «x86» for a 32 bit WOW process running on 64 bit Windows. See detecting OS 32/64 bit PROCESSOR_ARCHITEW6432 = %PROCESSOR_ARCHITECTURE% (but only available to 64 bit processes) PROCESSOR_IDENTIFIER Y Processor ID of the user’s workstation. PROCESSOR_LEVEL Y Processor level of the user’s workstation. PROCESSOR_REVISION Y Processor version of the user’s workstation. ProgramW6432 = %ProgramFiles% (but only available when running under a 64 bit OS) ProgramData C:\ProgramData ProgramFiles C:\Program Files or C:\Program Files (x86) ProgramFiles(x86) 1 C:\Program Files (x86) (but only available when running under a 64 bit OS) PROMPT Code for current command prompt format,usually $P$G
C:> PSModulePath %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ Public C:\Users\Public RANDOM Y A random integer number, anything from 0 to 32,767 (inclusive). %SessionName% Terminal servers only — for a terminal server session, SessionName is a combination of the connection name, followed by #SessionNumber. For a console session, SessionName returns «Console». SYSTEMDRIVE C: SYSTEMROOT By default, Windows is installed to C:\Windows but there’s no guarantee of that, Windows can be installed to a different folder, or a different drive letter.
systemroot is a read-only system variable that will resolve to the correct location.
Defaults in early Windows versions are C:\WINNT, C:\WINNT35 and C:\WTSRV TEMP and TMP User Variable C:\Users\ \AppData\Local\Temp
Under XP this was \ \Local Settings\Temp TIME Y The current time using same format as TIME. UserDnsDomain Y
User Variable Set if a user is a logged on to a domain and returns the fully qualified DNS domain that the currently logged on user’s account belongs to. USERDOMAIN USERDOMAIN_roamingprofile The user domain for RDS or standard roaming profile paths. Windows 8/10/2012 (or Windows 7/2008 with Q2664408) USERNAME USERPROFILE %SystemDrive%\Users\
This is equivalent to the $HOME environment variable in Unix/Linux WINDIR

%windir% is a regular User variable and can be changed, which makes it less robust than %SystemRoot%
Set by default as windir=%SystemRoot%
%WinDir% pre-dates Windows NT, its use in many places has been replaced by the system variable: %SystemRoot%

1 Only on 64 bit systems, is used to store 32 bit programs.

Unless stated otherwise, all the variables above are System variables

Environment variables are stored in the registry:

User Variables: HKEY_CURRENT_USER\Environment
System Variables: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

By default, files stored under Local Settings do not roam with a roaming profile.

Dynamic environment variables are read-only and are computed each time the variable is expanded. When all variables are listed with SET, these will not appear in the list. Do not attempt to directly SET a dynamic variable.

Shell variables

Variables for current shell session are created with the SET command and are available only to the current CMD shell. These are only stored in memory not the registry. Shell variables are destroyed when the current shell (CMD) exits.

Running the SET command with no options will display all shell variables but also all User and System environment variables.

If the SET command is used to modify the PATH, or if it is removed completely with PATH ; that will not affect any other programs or CMD sessions opened before or after the current one.

Undocumented Dynamic variables (read only)

%__APPDIR__% The directory path to the current application .exe, terminated with a trailing backslash. (Global) — discuss
%__CD__% The current directory, terminated with a trailing backslash. (Global)
%=C:% The current directory of the C: drive. ( See Raymond Chen’s explanation of this.)
%=D:% The current directory of the D: drive if drive D: has been accessed in the current CMD session.
%DPATH% Related to the (deprecated) DPATH command.
%=ExitCode% The most recent exit code returned by an external command, such as CMD /C EXIT n, converted to hex.
%=ExitCodeAscii% The most recent exit code returned by an external command, as ASCII. (Values 0-32 do not display because those map to ASCII control codes.)
%FIRMWARE_TYPE% The boot type of the system: Legacy, UEFI, Not implemented, Unknown Windows 8/2012.
%KEYS% Related to the (deprecated) KEYS command.
More detail on these undocumented variables can be found in this stackoverflow answer from Dave Benham.

Undocumented Dynamic variables (read/write)

%__COMPAT_LAYER% Set the ExecutionLevel to either RunAsInvoker (asInvoker), RunAsHighest (highestAvailable) or RunAsAdmin (requireAdministrator) for more see elevation and Q286705 / Application Compatibility Toolkit for other Compatibility Layers (colours,themes etc).

Pass variables between batch scripts

There are several ways to pass values between batch files, or between a batch file and the command line, see the CALL and SETLOCAL pages for full details.

A child process by default inherits a copy of all environment variables from its parent, this makes environment variables unsuitable for storing secret information such as API keys or user passwords, especially in rare occasions like crashes where a crash log will often include the full OS environment at the time of the crash. PowerShell/Get-Credential is a more secure approach.

If Command Extensions are disabled, the following dynamic variables will be not accessible:
%CD% %DATE% %TIME% %RANDOM% %ERRORLEVEL% %CMDEXTVERSION% %CMDCMDLINE% %HIGHESTNUMANODENUMBER%

“Men may be convinced, but they cannot be pleased against their will. But though taste is obstinate, it is very variable, and time often prevails when arguments have failed”

How the environment-building process works — Raymond Chen [MSFT].
PowerShell — Working with Environment variables.
User Shell Folders — Profile, Start Menu — Location of user profile folders.
Detecting 32 vs 64 bit Windows
CALL — Evaluate environment variables.
SET — View environment variables, set local variables.
SETX — Set environment variables.
Q100843 — The four types of environment variable.
Q286705 — Set compatibility variables in a batch file.
Q242557 — Registry Settings for Folder Redirection.
StackOverflow — Storing a Newline in a variable.

Читайте также:  Не монтирует раздел linux
Оцените статью