UPDATED 8/1/2023: On Windows 11 (and 10), environment variables are predefined names representing the path to certain locations within the operating system, such as a drive or a particular file or folder.
Environment variables can be helpful in many scenarios, but they’re particularly useful if you’re a network administrator or troubleshooting a device, as you can quickly navigate to certain locations without even knowing the username or full path to a system folder.
For example, instead of browsing a path like “C:\Users\UserName\AppData\Roaming,” you can open the “Run” command, type this variable “%APPDATA%,” and press Enter to access the same path. Or you can use the “%HOMEPATH%” variable to access the current user’s default profile folder location (where the system stores the folders for Desktop, Documents, Downloads, and OneDrive).
This guide will teach you the list of the most common environment variables you can use on Windows 11 (and on Windows 10).
Variable | Windows 10 and Windows 11 |
---|---|
%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 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 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 number from 0 through 32767. |
%OS% | Windows_NT |
Although you can use environment variables to access certain locations within Windows 11 quickly, you’ll typically use these variables when building a script or an application.
Keep in mind that some of the variables mentioned are not location-specific, including %COMPUTERNAME%
, %PATHEXT%
, %PROMPT%
, %USERDOMAIN%
, %USERNAME%
.
You can always view all the environment variables available on your device using the Get-ChildItem Env: | Sort Name
PowerShell command.
While this guide is focused on Windows 10 and 11, it’s important to note that these variables will also work on Windows 8.1, Windows 7, and Windows Vista.
Mauro Huculak is a
Windows How-To Expert and founder of
Pureinfotech
(est. 2010). With over 21 years as a technology writer and IT Specialist,
Mauro specializes in Windows, software, and cross-platform systems such as Linux, Android, and macOS.
Certifications:
Microsoft Certified Solutions Associate (MCSA),
Cisco Certified Network Professional (CCNP),
VMware Certified Professional (VCP),
and
CompTIA A+ and Network+.
Mauro is a recognized Microsoft MVP and has also been a long-time contributor to Windows Central.
You can follow him on
YouTube,
Threads,
BlueSky,
X (Twitter),
LinkedIn and
About.me.
Email him at [email protected].
В Windows 10 переменные среды — это предварительно определенные имена, представляющие путь к определенным местам в операционной системе, например к диску, конкретному файлу или папке.
Переменные среды могут быть полезны в ряде сценариев, они особенно полезны, если вы являетесь специалистом по ИТ или чините чужой компьютер, поскольку вы можете быстро перемещаться в определенные места, даже не зная имени пользователя или полного пути к системной папке.
Например, вместо перехода по следующему пути C:\Users\<UserName>\AppData\Roaming можно открыть команду «Выполнить» (клавиша Windows + R), ввести %APPDATA% и нажать клавишу Enter для доступа к тому же пути. Или вы можете использовать переменную %HOMEPATH% для доступа к местоположению папок по умолчанию для текущего пользователя — где операционная система хранит папки рабочего стола, документов, загрузок, OneDrive и т. Д.
Переменные среды по умолчанию в Windows 10
VARIABLE | WINDOWS 10 |
---|---|
%ALLUSERSPROFILE% | C:\ProgramData |
%APPDATA% | C:\Users\{имя пользователя}\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\{имя пользователя} |
%LOCALAPPDATA% | C:\Users\{имя пользователя}\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\{имя пользователя}\AppData\Local\Temp |
%TMP% | C:\Users\{имя пользователя}\AppData\Local\Temp |
%USERDOMAIN% | Пользовательский домен, связанный с текущим пользователем. |
%USERDOMAIN_ROAMINGPROFILE% | Пользовательский домен, связанный с перемещаемым профилем. |
%USERNAME% | {имя пользователя} |
%USERPROFILE% | C:\Users\{имя пользователя} |
%WINDIR% | C:\Windows |
%PUBLIC% | C:\Users\Public |
%PSModulePath% | %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ |
%OneDrive% | C:\Users\{имя пользователя}\OneDrive |
%DriverData% | C:\Windows\System32\Drivers\DriverData |
%CD% | Выводит текущий путь к каталогу. (Командная строка.) |
%CMDCMDLINE% | Выводит командную строку, используемую для запуска текущего сеанса командной строки. (Командная строка.) |
%CMDEXTVERSION% | Выводит количество текущих расширений командного процессора. (Командная строка. |
%COMPUTERNAME% | Выводит имя системы. |
%DATE% | Выводит текущую дату. (Командная строка.) |
%TIME% | Время выхода. (Командная строка.) |
%ERRORLEVEL% | Выводит число определяющих статус выхода предыдущей команды. (Командная строка.) |
%PROCESSOR_IDENTIFIER% | Идентификатор процессора |
%PROCESSOR_LEVEL% | Outputs processor level. |
%PROCESSOR_REVISION% | Вывод ревизии процессора. |
%NUMBER_OF_PROCESSORS% | Выводит количество физических и виртуальных ядер. |
%RANDOM% | Выводит случайное число от 0 до 32767. |
%OS% | Windows_NT |
Хотя вы можете использовать переменные среды для быстрого доступа к определенным местам в Windows 10, вы, как правило, будете использовать эти переменные при создании сценария или приложения.
Помните, что некоторые из упомянутых переменных не зависят от местоположения, в том числе % COMPUTERNAME%, %PATHEXT%, %PROMPT%, %USERDOMAIN%, %USERNAME%.
Хотя это руководство ориентировано на Windows 10, важно отметить, что эти переменные также будут работать в Windows 11, Windows 8.x, Windows 7 и Windows Vista.
- Environment variables are global system variables that are available to all users and programs running on the system. They store system-wide and user-specific values.
- You can view and manage environment variables from Settings > System > About > Advanced system settings > Environment Variables.
- To view all environment variables in Command Prompt, run “set“, or run “Get-ChildItem Env: | Sort Name” in PowerShell.
Most operating systems have environment variables, including Windows, MacOS, and Linux. Just like in a programming language, environment variables can be called upon to use their values that can store a number, a location, or any other value defined.
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, 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.
Table of Contents
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:
- Machine
- User
- Process
At the top, you have machine or system environment variables. These can be used across the entire system, and used for global variables, meaning changing the system variables will affect all users of the computer. Then there are user environment variables. This is defined individually for each user account and is limited to that account only and only affects the user currently logged in.
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.
Furthermore, each of these scopes has different types of variables, which are as follows:
- PATH: This variable stores a list of directories where your OS searches for executable programs. It’s crucial to run commands and launch applications from the command prompt and Run dialog.
- JAVA_HOME: This variable points to the installation directory of your Java Development Kit (JDK), a necessity for Java development and running Java applications.
- CLASSPATH: This variable tells your Java Virtual Machine (JVM) where to find user-defined classes and libraries, ensuring your Java code can access the necessary resources.
Please note that environment variables in Windows are not case-sensitive and are only written in upper case to distinguish between the variable name and the value.
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\Temp
- User: C:\Users\[Username]\AppData\Local\Temp
- Process: 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 path 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%”.
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:
- ALLUSERSPROFILE
- APPDATA
- COMPUTERNAME
- HOMEDRIVE
- HOMEPATH
- LOCALAPPDATA
- LOGONSERVER
- PROMPT
- PUBLIC
- SESSION
- SystemDrive
- SystemRoot
- USERDNSDOMAIN
- USERDOMAIN
- USERDOMAIN_ROAMINGPROFILE
- USERNAME
- USERPROFILE
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:
Variable Name | Value |
---|---|
%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_NT |
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:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
The user environment variables are stored at the following location:
Computer\HKEY_CURRENT_USER\Environment
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.
View Environment Variables from Settings App
Follow these steps to access the environment variables using the Settings app:
-
Navigate to the following:
Settings app >> System >> About
-
Now click Device Specifications to expand it.
Expand Device Specifications -
Now click Advanced system settings under Related links.
Open Advanced system settings -
From the pop-up System Properties window, switch to the Advanced tab, and then click Environment Variables.
Open Environment Variables -
The Environment Variables window will now open. Here, you can see the user variables at the top and the system/machine variables at the bottom.
Environment Variables window
View Environment Variables from Command Line
If you want to access the environment variables using the Command Line, here is how:
-
Run the following cmdlet in either the Command Prompt, Windows PowerShell, or the Run Command box to open the System Properties applet.
sysdm.cpl
Open System Properties applet -
From the pop-up System Properties window, switch to the Advanced tab, and then click Environment Variables.
Open Environment Variables -
The Environment Variables window will now open. Here, you can see the user variables at the top and the system/machine variables at the bottom.
Environment Variables window
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:
Get-ChildItem Env: | Sort Name
List Environment Variables in Command Prompt
You can also view the list of environment variables in the Command Prompt with the following basic command:
set
This command will list down all 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:
How to Create and Set/Edit 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:
-
Access the Environment Variables window using one of the given methods above. In this window, click New either under user variables or system variables, depending on which scope you want to create the variable in.
Create a new variable -
In the popup window, set a name for the variable and then enter its value. Once done, click OK.
Enter details for variable -
Back in the Environment Variable window, click OK again to save the changes.
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.
Set [VariableName]=[Value]
Permanent Environment Variable
If you want to create a permanent environment variable, then use this cmdlet instead:
Setx [VariableName] "[Value]"
Using third-party software
You can also manage environment variables using third-party tools and utilities. Here are a few that can be used with great convenience.
Rapid Environment Editor
Rapid Environment Editor (REE) provides a very user-friendly way of editing environment variables. It lists the system variables in the left pane and the user variables in the right pane, while the bottom pane will give details about the selected variable.
The best thing about REE is that it will also highlight a variable if its value has some errors. You can also back up the environment variable configuration from the file menu. Rapid Environment Editor comes with an installable program, as well as a portable one. If you are using the portable REE in Windows 7 or Windows 8, you will need to run the executable in the administrative mode so that it can make changes to the system configuration.
PathMan
PathMan is a very simple portable program, which will only edit the PATH environment variable. Since PATH is a variable that needs to be edited frequently, PathMan can help edit the Path environment variable directly from the USB drive.
Eveditor
Eveditor comes with an elegant and very user-friendly graphical user interface that resembles the look and feel of Windows Explorer. You can choose from a user variable or system variable from the pane on the left. The selection will be displayed on the right-hand pane. The details of the selected environment variable will be displayed in the bottom pane.
You can edit the selected variable, and upon clicking the “Set” button, the variable will be saved. Please note that you will need to run Eveditor with administrative privileges to save the environment variables successfully.
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: You should 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.
-
Access the Environment Variables window using one of the given methods above.
-
In the Environment Variables window, click on the variable that you want to remove and click Delete under the same section.
Delete environment variable -
Now click OK to save the changes.
The variable will now be removed from your PC.
Alternatively, you can use the Command Prompt to unset an environment variable. Simply use the set
command discussed above to empty the string. Here is an example:
set [VariableName]=
Leaving the command blank after “=” will set the string to empty. The environment variable will exist but will be of no use.
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:
-
Access the Environment Variables window using one of the given methods above.
-
Here, click on the variable that you want to edit and then click Edit under the same section.
Edit an environment variable -
From the Edit popup, make the changes you want to the name or the value of the variable, and then click OK.
Edit variable details -
Back on the Environment Variables window, click OK to save the changes.
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.
cd Env:
To get the complete list of environment variables and their values, use the following cmdlet:
Get-Item -Path Env:
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.
NewItem -Path Env:\[VariableName] -Value [Value]
To set the value of an existing variable, use this cmdlet:
Set-Item -Path Env:[VariableName] -Value "[Value]"
To delete an environment variable from the Env: drive, use this cmdlet:
Remove-Item -Path Env:\[VariableName]
Frequently Asked Questions (FAQs)
Is it safe to delete an environment variable?
The answer is both yes and no. Although deleting a default OS environment variable will have no performance repercussions, any apps or programs using that variable will no longer be able to look for the executables in the specified directories, or you won’t be able to use the shortcuts anywhere in the system to run an executable.
What does the PATH environment variable do?
The PATH environment variable can store multiple path values for different executable files. When an executable file is called, like “CMD,” the PATH variable tells it where to look for the cmd.exe file.
System and User Environment Variables have always been a complex topic of discussion for day-to-day Windows OS users. What do they do? A tutorial on the internet said to add a PATH variable, but what is it? Where do I find these variables? All of these questions will be answered shortly in this post. We’ve tried to give you a high-level overview of what System and User Environment Variables are and how you can utilize them.
In this post, we will discuss Environment Variables, System and User Environment Variables and how to add and modify them. Then, we will move on to Dynamic System Variables and see how to use them in the command prompt.
What is an Environment Variable In Windows OS
Environment Variable is formed up of two separate words, ‘Environment’ and ‘Variable’. Let’s discuss ‘variable’ first. It means that the entity can store a value and vary from computer to computer. Windows provides an ‘Environment’ for applications to execute and perform operations, and that is what makes the first word. Combining both, Environment Variables are those dynamic objects that store the values provided by the environment. Now, the environment provides values that help other programs in obtaining some crucial information about the system. There is an environment variable called ‘windir’ that corresponds to the directory where Windows is installed. To see this in action, open up an explorer window and type in ‘%windir%’ in the address bar. The Windows installation folder will open up.
Very similarly, you can make reference to the Windows directory using ‘windir’ variable in other programs and scripts. There are numerous other variables that can be accessed, ‘TEMP’ or ‘TMP’ is the variable that points to the directory where all temporary files are stored. The most popular ‘Path’ variable is the one that points to the directories containing executable files. So that you can run a program from the Command Prompt in any other directory. We’ve explained Path later on in this post. All these variables come in handy when you are developing something or using the shell a lot.
Very similar to how the Registry works on Windows, we have System and User Environment Variables. The system variables are system-wide accepted and do not vary from user to user. Whereas User Environments are configured differently from user to user. You can add your variables under the user so that other users are not affected by them.
Just for your information, since we are discussing the topic in depth. System Variables are evaluated before User Variables. So if there are some user variables with the same name as system variables, then user variables will be considered. The Path variable is generated in a different way. The effective Path will be the User Path variable appended to the System Path variable. So, the order of entries will be system entries followed by user entries.
Read: How to use Environment Variable Editor in PowerToys?
How to add & modify Environment Variables
A small warning before we go deeper. Create a system restore point, and try not to tamper with the existing settings configured for your system. Until you are very sure about your actions. To open the ‘Environment Variables’ Window, follow these steps:
- Right-click ‘This PC’ icon and select ‘Properties’.
- Now in this window, select ‘Advanced System Settings’ from the left part.
- Hit the last button saying ‘Environment Variables’ to open our destined window.
Once you’ve opened this up, you will be able to view User and System variables separately. The variable name is in the first column and its value in the second. The corresponding buttons below the table let you ‘Add’, ‘Edit’ and ‘Delete’ these variables.
Read: Environment Variables not working in Windows 11
Using the Path variable
Path is the most used environment variable. As I mentioned, it points to directories that contain executable files. Once you’ve correctly set up your Path variable, you can use these executables from anywhere in the system. Let’s try to understand this with an example. Open up the environment variables window and look for ‘Path’ in system variables.
Click on ‘Edit’ and then click on ‘New’ without playing around with other controls right now. Now click browse and select a folder that has your desired executable file. Click ‘Ok’ and save everything. I added ‘Visual Studio Code’ executable to the path.
Now to run your application, open up Command Prompt and type in the name of the executable file that was in the folder. You can provide additional arguments if the program supports it. The program will run from the command prompt without actually being in the directory from where you executed the command. That is the beauty of the Path variable.
Read: How to add or edit a PATH Environment Variable in Windows.
List of all Environment Variables
Open the command prompt and type ‘SET’ and hit Enter. The entire list of variables with their current values will be displayed, and you can refer to it to make changes to your computer.
Read: How to see Names and Values of Environment Variables in Windows
Dynamic Environment Variables
Unlike conventional variables, dynamic environment variables are provided by the CMD and not by the system. You cannot change the values of these variables and they expand to various discrete values whenever queried. We usually use these variables for batch processing and these are not stored in the environment. Even the ‘SET’ command will not reveal these variables. Some of the dynamic environment variables are listed below.
Read: How to add Environment Variables to Context Menu.
List of environment variables in Windows 11/10
%APPDATA% – C:\Users\<username>\AppData\Roaming
%ALLUSERSPROFILE% – C:\ProgramData
%CD% – Typing in this command will give you the current directory you are working in.
%COMMONPROGRAMFILES% – C:\Program Files\Common Files
%COMMONPROGRAMFILES(x86)% – C:\Program Files (x86)\Common Files
%COMMONPRGRAMW6432% – C:\Program Files\Common Files
%CMDEXTVERSION% – This variable expands to the version of the command-line extensions.
%COMSPEC% – C:\Windows\System32\cmd.exe
%DATE%: – This variable will give you the current date according to date format preferences.
%ERRORLEVEL% – Determines the error level set by last executing command.
%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
%TIME% – Similarly, it gives you current time according to the time format preferences.
%TMP% – C:\Users\<username>\AppData\Local\Temp
%TEMP% – C:\Users\<username>\AppData\Local\Temp
%USERNAME% – <username>
%USERPROFILE% – C:\Users\<username>
%USERDOMAIN% – Userdomain associated with current user.
%USERDOMAIN_ROAMINGPROFILE% – Userdomain associated with roaming profile.
%WINDIR% – C:\Windows
%PUBLIC% – C:\Users\Public
%PSMODULEPATH% – %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
%ONEDRIVE% – C:\Users\<username>\OneDrive
%DRVERDATA% – C:\Windows\System32\Drivers\DriverData
%CMDCMDLINE% – Outputs command line used to launch the current Command Prompt session. (Command Prompt.)
%COMPUTERNAME% -Outputs the system name.
%PROCESSOR_REVISION% – Outputs processor revision.
%PROCESSOR_IDENTIFIER% – Outputs processor identifier.
%PROCESSOR_LEVEL% – Outputs processor level.
%RANDOM% – This variable prints a random number from 0 through 32767
%NUMBER_OF_PROCESSORS% – Outputs the number of physical and virtual cores.
%OS% – Windows_NT
This was pretty much about System and User Environment Variables on Windows. Windows does come with a lot more variables – don’t forget to check them using the ‘SET’ command.
TIP: Rapid Environment Editor is a powerful Environment Variables Editor for Windows.
Different programs and processes require different environments to run. On a single machine, Windows needs to make sure that all programs and processes can access the environments they need.
To do this, Windows needs to know the kind of environment every program requires to work. Windows must store this information somewhere for easier retrieval. Environment variables make that possible.
Environment variables are, in short, data storing mechanisms.
Let’s dig a little deeper to see how environment variables work and how you can create, edit, and delete them effectively.
What Are Environment Variables in Windows 10?
Environment variables are dynamic variables that store data related to creating different environments for different programs and processes.
To understand them better, let us take the example of a program that needs to use a built-in Windows tool to run.
For the program to use the tool, the program needs to know the tool’s location to access it. The program also needs to find out if it has permission to use the tool or not. Similarly, there are things that a program needs to know before it can use the tool.
So, a program can access all of this information by asking Windows. Windows then looks up environment variables (EVs) for this data and creates an environment in which that program can run.
In other words, EVs store data that is accessible to every program and process running on the system across all users. The data these variables store helps the programs run in the environment they were designed for.
Some of the most important EVs on Windows include PATH, HOMEPATH, and USERNAME. All of these variables contain values that any user and process of the system can access at any time. For instance, the USERNAME environment variable contains the name of the current user. Windows can look up this variable whenever it needs to find out the name of the current user.
How to Set Environment Variables in Windows 10?
First things first, if you want to set system-wide EVs, you need to have administrative privileges. So, if you are not the admin, inform your system administrator and ask for their help.
Now that you have admin privileges:
- Type Advanced system settings in the Start menu search box and select the Best match.
- In the System Properties box, click on Environment Variables to open the Environment Variables panel.
The EVs panel lists two types of variables depending upon your need. If you want to change EVs for the current user only and don’t want the changes to reflect system-wide, you will change User variables.
On the contrary, if you want system-wide changes, you will change System variables.
Let’s say you’ve just installed Java and want to add the java path to the EVs. To do this:
- Click on New under the User/System variables. This will open up the New User Variable box.
- Enter JAVA_HOME in the Variable name field and browse to the directory where you’ve installed Java to populate the path in Variable value.
Pressing OK will add the JAVA_HOME variable to the PATH variable.
How to Edit Environment Variables
To edit different environment variables, select any variable from the list. Then, press Edit. This will open up the Edit environment variable panel. Here you can create, delete, and edit variables.
From the list of variables, select the one that you want to modify and click on Edit. Afterward, you can change the variable value to anything you like.
You can also delete the variables in a similar fashion.
What Is the Windows PATH Variable and How Can I Change it?
In simple terms, the PATH variable is an address book of programs and commands on your computer. Whenever you have a new program on your computer that you want to run from the command line interface, you must specify its address in the PATH variable.
A thing to remember here, not all programs are in the PATH environment variable. Only the programs that are meant to be used from the command line interface appear in the PATH variable. So, programs intended to be used from a Graphical User Interface don’t have their addresses in the PATH variable.
The way the process works involves Windows looking up the address for a certain command. Whenever you issue a command on a command line, Windows first searches the current directory for the command. If the OS can’t find it in the current directory, it looks up the PATH variable to find the address.
To enter an address in the PATH variable, the process is the same as before. Open up the Environment Variable box, select the PATH variable, and click on Edit.
In the Edit box, you can add, remove, and edit directories.
One final thing to remember, the PATH variable is not the same for every user on a system. So different users can list different directories without changing the variable for every user. So, if you want a tool to be available for every user, you have to edit the PATH variable under the System Variables.
Environment Variables in Windows 10 Store Data that Programs Need to Work
Programs need data to work. To make sure that data is available efficiently, Windows stores this data in global variables that all programs can access. These global variables are Environment Variables.
You can add, edit, and remove Environment Variables inside the Advanced System Settings panel.
Furthermore, if you have more than one user on a machine, user Environment Variables will be different for each user. For instance, one user may have listed a command under the PATH variable that won’t be available for other users.
On the other hand, system EVs are available for all users. These variables require admin privileges to edit or delete.
In short, EVs are Windows’ way to store important data. So, be sure you know what you are doing before modifying them.