≡ Menu

Windows environment variables

Command to list variables

Set command shows the list of all environment variables with assigned values.

You can also restrict the command to display only the variables starting with a common prefix. For example, to list all variables starting with ‘s’ you can run the below command.

set s

Example:

C:\>set s
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS

Environment variables can be used in batch files to find the corresponding value. For example, to get the user login id, we can use %username% variable.

Important environment variables

%Username% : Used to find the id of the user logged in
%computername%: Name of the computer. It gives NetBios name not the FQDN name.
%path% : List of directories windows need to look for finding an executable
%systemdrive% : Installation drive for the currently running OS.
%userdomain% : Domain where the current logged in user account is created
%PROCESSOR_ARCHITECTURE% : Architecture model of the processor (AMD64/X86)
%windir% : Directory for the Windows OS files. If the OS is installed on C: drive, this variable would point to C:\Windows
%TMP%, %TEMP% : Points to folder that applications can use to create temporary files.

Complete list of environment variables

ALLUSERSPROFILE
APPDATA
CommonProgramFiles
CommonProgramFiles(x86)
CommonProgramW6432
COMPUTERNAME
ComSpec
DEFLOGDIR
FP_NO_HOST_CHECK
HOMEDRIVE
HOMEPATH
LOCALAPPDATA
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramData
ProgramFiles
ProgramFiles(x86)
ProgramW6432
PROMPT
PSModulePath
PUBLIC
SESSIONNAME
SystemDrive
SystemRoot
TEMP
USERDNSDOMAIN
USERDOMAIN
USERNAME
userpath
USERPROFILE
VSEDEFLOGDIR
windir

The list may vary slightly on your computer depending on the OS edition and the list of applications you installed on your computer.

In addition to the above, there are few more environment variables which are not displayed by ‘set’ command. But these can be used in windows command line or in batch files. They are listed below.

%CD%  : can be used to get the current directory
%DATE%    : can be used to get the date
%TIME%   : can be used to get the time
%RANDOM%  : can be used to get random number between 0 and 32767
%ERRORLEVEL%  : can be used to get the error level value
%CMDEXTVERSION% : gets current Command Processor Extensions
%CMDCMDLINE% : gets the command line executable that invoked the command prompt.
%HIGHESTNUMANODENUMBER%  : Gets the highest numa node number on this computer

How to modify environment variables values?

We can use ‘Set’ command to change environment variables from command line.

3 comments… add one
  • Firefox264

    Thank you :)

  • Al

    Good information. Thanks for gathering this here.

  • Mathew

    Great list here I was able to add a few to mine. Here are a few I had that you missed and I think are helpful… I tested these on Win7
    %HOMESHARE% returns path to your HOMEDRIVE
    %PSMODULEPATH% returns the path to your powershell module.

    I never found a use for this one…
    %CMDCMDLINE%

    And %TMP% is equal to %TEMP% or at least it is on every system I have tried it on.

Leave a Comment