The environment variables were introduced with Windows 95, and have since gone through many iterations with every Windows release. These can be used to access certain directories quickly, rather than enter the complete paths. Environment variables can be edited and manipulated, or you can even add new ones. In this article, we discuss the many different Windows environment variables and what they do, and all that you need to know about them. This guide applies to all versions of Windows, including Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10, and Windows 11.
What are Environment Variables
Environment variables are variables that can be used across your system. Just like in programming, variables contain a value that can be changed or called when needed. Environment variables are the same, but can be used across the entire scope. You can use environment variables in Windows to store frequently used locations, so you don’t have to type them out each time, or temporarily change the way a program behaves. Environment variables are normally used in scripts or programs/apps. For example, you can create an environment variable called TEMP that points to a different folder than the default TEMP folder Windows uses. Then, when a program needs to store temporary files, it will use the TEMP folder you specified instead of the default one. Tip: If you are using Linux or MacOS, the environment variables can be set in the .bashrc or .profile files. There are 3 types/scopes of environment variables in the hierarchy: At the top, you have machine or system environment variables. This can be used across the entire system, regardless of which user is logged in. Then there are user environment variables. This is defined individually for each user account and is limited to that account only. Then you have the process variables which are only limited to the processes and cannot be edited or created. The end-user does not see or have anything to do with the process variables. Additionally, if there is an environment variable of the same name in more than one scope, then the variable in the lower scope will supersede the value of the one higher in the hierarchy. For example, the common environment variable “TEMP” is available in all scopes with the following values:
Machine: C:\Windows\TempUser: C:\Users[Username]\AppData\Local\TempProcess: C:\Users[Username]\AppData\Local\Temp
Hence, using the “Temp” variable will call for the value set for the process scope. If there is no variable by the name “Temp” in this scope, then it will use the value for the user scope, and so on. You can use these variables to access a directly quickly. For example, typing in “%HOMEPATH%” in the Run Command box will open the user’s home directory. You can also edit this variable to include a sub-directory of the path, like opening the user account’s desktop by typing in “%HOMEPATH%\Desktop%”.Using an environment variable to open its subdirectory
What are Environment Variable Scopes
As we mentioned earlier, there are 3 scopes for environment variables: Machine/System, user, and process. These scopes define the limitations of the variables and where they can be used. Below you’ll find a more detailed explanation of the different types of environment variable scopes.
System/Machine
The environment variables defined inside this scope can be used by anyone on the system. These types of variables are associated with the running instance of Windows. Any user account can read these, set, change, or delete them, provided they have administrative rights.
User
The environment variables defined within this scope are only user-specific and might be different for each user account. This is associated with the current user. User variables overwrite machine-scoped variables with the same name.
Process
Environment variables in this scope are a combination of machine and user scopes in addition to some dynamically-created variables by the Windows OS. Now that you know what environment variables are and how they work, let us see which variables are available in a Windows OS. Here is a list of the process variables which are available in this scope:
ALLUSERSPROFILEAPPDATACOMPUTERNAMEHOMEDRIVEHOMEPATHLOCALAPPDATALOGONSERVERPROMPTPUBLICSESSIONSystemDriveSystemRootUSERDNSDOMAINUSERDOMAINUSERDOMAIN_ROAMINGPROFILEUSERNAMEUSERPROFILE
Complete list of Windows Environment Variables
Below is a complete list of the environment variables that you will find inside the Windows operating system by default:Default Windows Environment VariablesVariable NameValue%ALLUSERSPROFILE%C:\ProgramData%APPDATA%C:\Users{username}\AppData\Roaming%COMMONPROGRAMFILES%C:\Program Files\Common Files%COMMONPROGRAMFILES(x86)%C:\Program Files (x86)\Common Files%CommonProgramW6432%C:\Program Files\Common Files%COMSPEC%C:\Windows\System32\cmd.exe%HOMEDRIVE%C:%HOMEPATH%C:\Users{username}%LOCALAPPDATA%C:\Users{username}\AppData\Local%LOGONSERVER%\{domain_logon_server}%PATH%C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem%PathExt%.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc%PROGRAMDATA%C:\ProgramData%PROGRAMFILES%C:\Program Files%ProgramW6432%C:\Program Files%PROGRAMFILES(X86)%C:\Program Files (x86)%PROMPT%$P$G%SystemDrive%C:%SystemRoot%C:\Windows%TEMP%C:\Users{username}\AppData\Local\Temp%TMP%C:\Users{username}\AppData\Local\Temp%USERDOMAIN%Userdomain associated with the current user.%USERDOMAIN_ROAMINGPROFILE%Userdomain associated with roaming profile.%USERNAME%{username}%USERPROFILE%C:\Users{username}%WINDIR%C:\Windows%PUBLIC%C:\Users\Public%PSModulePath%%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules%OneDrive%C:\Users{username}\OneDrive%DriverData%C:\Windows\System32\Drivers\DriverData%CD%Outputs current directory path. (Command Prompt.)%CMDCMDLINE%Outputs command line used to launch current Command Prompt session. (Command Prompt.)%CMDEXTVERSION%Outputs the number of current command processor extensions. (Command Prompt.)%COMPUTERNAME%Outputs the system name.%DATE%Outputs current date. (Command Prompt.)%TIME%Outputs time. (Command Prompt.)%ERRORLEVEL%Outputs the number of defining exit status of the previous command. (Command Prompt.)%PROCESSOR_IDENTIFIER%Outputs processor identifier.%PROCESSOR_LEVEL%Outputs processor level.%PROCESSOR_REVISION%Outputs processor revision.%NUMBER_OF_PROCESSORS%Outputs the number of physical and virtual cores.%RANDOM%Outputs random numbers from 0 through 32767.%OS%Windows_NTList of all Windows Environment Variables
Where are Environment Variables Stored
The environment variables are stored in 2 places in the Windows Registry; one for the system and one for individual users. The system environment variables are stored at the following location: The user environment variables are stored at the following location: You can also export the “Environment” key using its context menu to import the environment variables on another Windows computer, or vice versa. Now that you know where they are stored, you may have a look at them. However, it is strongly recommended that you do not add or change environment variables using the Windows Registry. This is because any running processes will not see variable changes in the registry. Processes only see the registry variables and values that are present when the process was started unless Windows notifies them that there has been a change. If you want to add or make changes to the environment variables, keep reading this post.
How to View/Access Windows Environment Variables
You can view and access Windows environment variables in multiple ways. Pick the method you like best from below.
Access Environment Variables from Settings App
Follow these steps to access the environment variables using the Settings app:
Access Environment Variables from Command Line
If you want to access the environment variables using the Command Line, here is how:
List Environment Variables in PowerShell
Alternative to the methods discussed above, you can also list the environment variables in PowerShell using a simple cmdlet. Run the following command in an elevated PowerShell instance and it will display all of the environment variables on your computer:
View Value for Environment Variable using Command Prompt
If you access the environment variable using any of the given methods above, then you can see their values as well. Another method to view the value of an environment variable is through the Command Prompt. Simply type in “echo” followed by the environment variable name in the “%” sign in an elevated Command Prompt and you will then see its value(s), as in this image:Display environment variable value
How to Create and Set Environment Variables in Windows
From System Properties
You may need to create a new environment variable or modify an existing one in the Windows OS to be used for programming purposes or to use Java. Whatever the reason, follow these steps to create a new environment variable using the GUI: The variable will now be created, and you can now use it in your code, or access the folder by concatenating a “%” sign on the front and back of it.
From Command Prompt
You can also create a new environment variable using the Command Prompt, and define its value(s). You can create both a temporary variable that only lasts until the instance is closed or the system is rebooted, or a permanent variable that will always remain unless explicitly deleted. Once you create the variable, you can access it immediately. There’s no need to restart the computer for the changes to take effect. Note: These methods create a user environment variable and not a system variable.
Temporary Environment Variable
Use the following cmdlet in an elevated Command Prompt to create a temporary variable while replacing [VariableName] with a custom name for the variable, and [Value] with the value that you want to define for the variable, which can be a string or a number.
Permanent Environment Variable
If you want to create a permanent environment variable, then use this cmdlet instead:
How to Delete an Environment Variable in Windows
If you no longer need an environment variable, you can simply delete it. One concern while deleting a variable is whether it is safe. The answer is both yes and no. Nothing happens when an environment variable is deleted, except that the apps, program, and other elements no longer know where to look for an item when it is called upon. Other than that, it has no impact on the system’s performance. That said, we still think that you should be extremely careful when deleting a variable. If you still wish to continue to remove an environment variable, follow these steps: Note: It is advisable that you create a system restore point before proceeding so that your system can be reverted to previous settings in case things do not go as planned. The variable will now be removed from your PC.
How to Edit an Environment Variable in Windows
You can also edit an environment variable. Its name can be changed as well as its value. However, it is recommended that you do not edit the default Windows environment variables, or else the apps and programs using those variables might no longer work. That said, the “PATH” variable stores several paths to directories for executable files. You can safely add more directory paths to this variable without causing an issue. Follow these steps to edit an environment variable in Windows:
What is the PATH Environment Variable
Earlier in this post, we mentioned the PATH environment variable. The PATH variable is perhaps the most-used variable out of the lot. The PATH variable stores multiple entries (or values). Those values specify the directories in which the executable programs are located on the system so that they can be started without knowing and typing the whole path to the file on the command line.
How to Manage Environment Variables using PowerShell Env
The PowerShell has a virtual drive known as the “PS Drive.” It is a data store location that you can access like a file system drive in Windows PowerShell. Using this drive, we can manage different aspects of the environment variables. A PS drive allows you to treat environment variables as if they are a file system through the Env: drive. Below you’ll find the guidelines to perform different variables-related tasks using the Env: drive. To begin, you must first switch to the ENv: drive. To do that, type in the following in the PowerShell window. To get the complete list of environment variables and their values, use the following cmdlet: You can also create new environment variables from the Env: drive by using this cmdlet. Replace [VarableName] with a name for the variable, and [Value] with the value you want to set for the variable. To set the value of an existing variable, use this cmdlet: To delete an environment variable from the Env: drive, use this cmdlet: Also see:
User vs. System Environment Variables: Do User Variables Override System VariablesHow To Create Custom Environment Variables in Windows 102 Easy Ways To Manage Environment Variables in Windows 10Ultimate Guide To Creating Windows Preinstallation Environment (WinPE)How to Install And Check Python Version In Windows, Mac, & Linux