What is an environment variable in Windows? An environment variable is a dynamic “object” containing an editable value which may be used by one or more software programs in Windows.
In this note i am showing how to list environment variables and display their values from the Windows command-line prompt and from the PowerShell.
Cool Tip: Add a directory to Windows %PATH% environment variable! Read More →
The environment variables in Windows can be printed using the Windows command-line prompt (CMD) or using the PowerShell.
Windows Command-Line Prompt (CMD)
List all Windows environment variables and their values:
C:\> set
“Echo” the contents of a particular environment variable:
C:\> echo %ENVIRONMENT_VARIABLE%
Windows PowerShell
Print all Windows environment variables (names and values):
PS C:\> gci env:* | sort-object name
Show the contents of a particular environment variable:
PS C:\> echo $env:ENVIRONMENT_VARIABLE
Cool Tip: Set environment variables in Windows! Read More →
Was it useful? Share this post with the world!
- 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.cplOpen 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.
Full List of Environment Variables in Windows 10
Information
**Environment variables** are a set of dynamic named values that can affect the way running processes will behave on a computer. The variables can be used both in scripts and on the command line. Environment variables makes it easy when certain standard directories and parameters need to be referenced but where the actual locations or names can vary from computer to computer.
This tutorial will show you a complete list of environment variables that can be used to reference standard directories and parameters in Windows 10.
Note
User environment variables are stored in the registry key below:
HKEY_CURRENT_USEREnvironment
System environment variables are stored in the registry key below:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment
You can open a Command Prompt, type set, and press Enter to display all current environment variables on your PC.
You can open PowerShell, type Get-ChildItem Env:, and press Enter to display all current environment variables on your PC.
Table of Environmental Variables
| Environment Variables | Values (may vary) |
|---|---|
| %ALLUSERSPROFILE% | C:ProgramData |
| %APPDATA% | C:Users(user-name)AppDataRoaming |
| %CD% | Current directory full path |
| %CMDCMDLINE% | Returns exact command line used to start current cmd.exe session. |
| %CMDEXTVERSION% | Number of current command processor extensions. |
| %CommonProgramFiles% | C:Program FilesCommon Files |
| %CommonProgramFiles(x86)% | C:Program Files (x86)Common Files |
| %CommonProgramW6432% | C:Program FilesCommon Files |
| %COMPUTERNAME% | BRINK-PC |
| %COMSPEC% | C:WindowsSystem32cmd.exe |
| %DATE% | Current date in format determined by Date command |
| %ERRORLEVEL% | Number defining exit status of previous command or program |
| %HOMEDRIVE% | C: |
| %HOMEPATH% | C:Users(user-name) |
| %LOCALAPPDATA% | C:Users(user-name)AppDataLocal |
| %LOGONSERVER% | \MicrosoftAccount |
| %NUMBER_OF_PROCESSORS% | 8 |
| %OS% | Windows_NT |
| %PATH% | C:\WINDOWS C:WINDOWS\system32 C:WINDOWS\System32\Wbem C:\Windows\system32\WindowsPowerShell\v1.0 |
| %PATHEXT% | COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC |
| %PROCESSOR_ARCHITECTURE% | AMD64 |
| %PROCESSOR_IDENTIFIER% | Intel64 Family 6 Model 60 Stepping 3, GenuineIntel |
| %PROCESSOR_LEVEL% | 6 |
| %PROCESSOR_REVISION% | 3c03 |
| %ProgramData% | C:ProgramData |
| %ProgramFiles% | C:Program Files |
| %ProgramFiles(x86)% | C:Program Files (x86) |
| %ProgramW6432% | C:Program Files |
| %PROMPT% | Code for current command prompt format. Code is usually $P$G |
| %PSModulePath% | C:Windowssystem32WindowsPowerShellv1.0Modules |
| %PUBLIC% | C:UsersPublic |
| %RANDOM% | To get random number between 0 and 32767 |
| %SessionName% | When logging on directly to machine, returns «Console». When client connects via terminal server session, is combination of connection name, followed by pound symbol {#} and session number. |
| %SystemDrive% | C: |
| %SystemRoot% | C:Windows |
| %TEMP% | C:Users(user-name)AppDataLocalTemp |
| %TIME% | Current time in format determined by Time command |
| %TMP% | C:Users(user-name)AppDataLocalTemp |
| %USERDOMAIN% | BRINK-PC |
| %USERDOMAIN_ROAMINGPROFILE% | BRINK-PC |
| %USERNAME% | (user-name) |
| %USERPROFILE% | C:Users(user-name) |
| %WINDIR% | C:Windows |
Credits:
Brink
Administrator
Related Tutorials
- Complete List of Windows 10 CLSID Key (GUID) Shortcuts
- Complete List of Windows 10 Shell Commands
- List of Rundll32 Commands for Windows 10
on October 16, 2011
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.
In computer programming, variables are the storage locations for values, and the values themselves can be anything. It could be a number, a filename, or some other piece of data. In a similar fashion, there are things called Environment Variables in your Operating System.
Environment Variables are global variables that store values linked to the current working environment and can be utilized by the operating system and other applications to retrieve necessary operating system information. Environment Variables are also known as env variables. Environment Variables are available in Windows, Mac, and Linux.
Table of Contents
- List of Environment variables in Windows Environment
- List environment variables using Command Line
- List environment variables using Powershell
- Using reg query command in Command Prompt
- List of Environment variables in Linux Environment
- List of Environment variables in macOS Environment
- Conclusion:
They are created as pairs consisting of a number and a value, and both the operating system and the application are able to access those values. The General Format of environment value looks like this:
Variable1 = C:\xyz
Variable2 = 6
variable2 ='val1:val2'
variable4 = val1;val2
...
These types of environment variables can be viewed, created, edited, and deleted. Environment Variable in general helps applications to know which directory to install installable files, and where to find user and system settings.
Some of the environment variables are PATH, USER, HOME, UID, SHELL, TERM, EDITOR, etc.PATHTEXT, OS, TEMP,SYstemRoot.PATH is a popular Environment variable that is available in Windows, Mac, and Linux.
If you want to know what environment variables are used in various OS then I will guide you on this.
List of Environment variables in Windows Environment
There are actually two types of environment variables in Windows. They are :
1. Local/User Environment Variable: User Variables store information that is unique to the logged-in user and are only relevant during the current session. They have located under the «HKEY_CURRENT_USER/Environment» path in the Registry
2. System Environment Variable: Because they are set uniformly across all of your computer’s users, system variables don’t contain any user-specific data. All user accounts are affected by these global variables.They are located under «HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/ControlSession /ManagerEnvironment» path in Registry
There is various way to list environment variables in windows. Let’s discuss some of them.
List environment variables using Command Line
In the command prompt type :
SET
and press Enter.
Some of the most common environment variables:
| Environment Variables | Description |
| %APPDATA% | AppData contains data and settings of various installed programs on your PC. |
| %COMPUTERNAME% | The unique identifier is given to your computer |
| %HOMEPATH% | HomePath describes the path for the user’s personal files. It contains user files like downloads, Desktop, Documents, Videos, Picture, Contacts, and many more. |
| %PATH% | The PATH variable provides the directories on the machine where executable programs can be found. |
| %CD% | Returns the current directory string. |
| %DATE% | The most recent date, formatted according to the Date command. |
| %LOGONSEVER% | This function brings back the name of the domain controller that was responsible for validating the current logon session. |
| %NUMBER_OF_PROCESSORS% | This number indicates how many processors are currently installed on the computer. |
| %OS% | This function returns the name of the operating system. |
| %PROMPT% | The directory in which the operating system is stored is returned by this function. |
| %WINDIR% | The directory in which the operating system is stored is returned by this function. |
| %USERNAME% | This function gets you the name of the user who is logged in at the moment. |
| %RANDOM% | It returns a random decimal number between 0 and 32767. |
If you have a large number of system and user variables in environment variables then SET displays all at a time. But if you want one page and then one line at a time then try this:
SET | more
If you want to save this variable for a future look then you can save it in a text file with the following command.
SET > any_name.txt
Here, I have used output.txt as the file name, and this file gets saved under C:\User\Dell path and contain output.txt look like this:
If you want help and wants to know more about set cmdlet then type the below command in command prompt for help:
set /?
Note: All commands used here are case insensitive. So, Get-ChildItem Env: is equivalent to get-childitem env:
List environment variables using Powershell
Get-ChildItem (GCI) is a useful cmdlet that is used to get items and, if the item is a container, it will get child items that are available inside the container.
You can simply type below one line to get all environment variables.
Get-ChildItem Env:
or Simply
gci env:
As you can see, some lines of the output are truncated. If you want to get the full output without any truncation, use the cmdlet below.
gci Env: | Format-Table -Wrap -AutoSize
or
Get-ChildItem Env: | Format-Table -Wrap -AutoSize
The gci env: cmdlet retrieves all environment variables, which are then passed through the pipeline(|) to Format-Table and displayed in a table. The AutoSize option adjusts column widths to avoid truncation.-Wrap Displays text that exceeds the column width in the new line without truncation.
Below, we can see that no lines in the output are truncated, as they were previously.
Using reg query command in Command Prompt
If you just want System variables then type below in the command prompt
reg query «HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment»
If you just want User variables then type below in the command prompt.
reg query HKEY_CURRENT_USER\Environment
List of Environment variables in Linux Environment
You can use the below cmdlet in Linux for getting environment variables. I am testing in ubuntu and it must work in other distributions of Linux.
printenv
In Linux, you can simply use the below command for displaying the list of environment variables.
env
It is not possible to view all bash variables when using the env command since it will only show a list of environment variables that have been exported.
List of Environment variables in macOS Environment
For macOS, we can use printenv for displaying all environment variables.
printenv
Conclusion:
In this approach, we may get a list of all the environment variables in major operating systems such as Windows, Linux, and Mac.
