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 set an environment variable in Windows from the command-line prompt (CMD) and from the Windows PowerShell.
In the examples below i will set an environment variable temporary (for the current terminal session only), permanently for the current user and globally for the whole system.
Cool Tip: Add a directory to Windows %PATH%
environment variable! Read More →
Set Environment Variable For The Current Session
Set an environment variable for the current terminal session:
# Windows CMD C:\> set VAR_NAME="VALUE" # Windows PowerShell PS C:\> $env:VAR_NAME="VALUE"
Print an environment variable to the console:
# Windows CMD C:\> echo %VAR_NAME% # Windows PowerShell PS C:\> $env:VAR_NAME
Cool Tip: List Windows environment variables and their values! Read More →
Set Environment Variable Permanently
Run as Administrator: The setx
command is only available starting from Windows 7 and requires elevated command prompt. It works both for the Windows command-line prompt (CMD) and the Windows PowerShell.
Permanently set an environment variable for the current user:
C:\> setx VAR_NAME "VALUE"
Permanently set global environment variable (for all users):
C:\> setx /M VAR_NAME "VALUE"
Info: To see the changes after running setx
– open a new command prompt.
Was it useful? Share this post with the world!
Windows set env variable from the command line
- Open command line.
set API_KEY=123
-
echo %API_KEY%
should print yourAPI_KEY
. - This env variable is set for the context of the current cmd line.
Windows set env variable permanently using the command line
- Open the command line as admin.
setx API_KEY "123" /M
- Close the current shell. Open a new shell.
-
echo %API_KEY%
should print yourAPI_KEY
. - This env variable is set for all future shell instances permanently for your system.
WSL Linux set env variable from a bash terminal
- Launch your wsl instance.
$ API_KEY=123
-
$ echo $API_KEY
should print yourAPI_KEY
.
WSL Linux set env variable permanently from a bash terminal
- Launch your wsl instance.
$ sudo vim ~/.bashrc
- Enter your password.
- Press
i
to go into edit mode. Go to the end of the file using arrow key. - Add your variable as
API_KEY=123
at the end of the file. If your variable has spaces, use quotes.Example —API_KEY= 'My Key'
- Press
esc
key to get out of edit mode. - Enter
:wq
and press enter . This will save and close the file. -
$ source ~/.bashrc
will load your recent changes into your current shell. -
$ echo $API_KEY
should print yourAPI_KEY
.
This post was originally published at https://www.jskap.com/blog/set-environment-variables-windows-wsl-linux/
👋 Hi! I’m Kapil. I am always chatty about building things, sharing my learnings, freelancing. Come say hi to me at https://twitter.com/kapilgorve
- SS64
- CMD
- How-to
Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
Syntax SET variable SET variable=string SET "variable=string" SET "variable=" SET /A "variable=expression" SET /P variable=[promptString] SET " Key variable A new or existing environment variable name e.g. _num string A text string to assign to the variable. /A Arithmetic expression see full details below. /P Prompt for user input.
Variable names are not case sensitive but the contents can be.
It is good practice to avoid using any delimiter characters (spaces, commas etc) in the variable name.
Delimiter characters can be used in the value if the complete assignment is surrounded with double quotes to prevent the delimiter being interpreted.
Any extra spaces around either the variable name or the string, will not be ignored, SET is not forgiving of extra spaces like many other scripting languages. So use SET alpha=beta, not SET alpha = beta
The first character of the name must not be numeric. It is a common practice to prefix variable names with either an underscore or a dollar sign _variable or $variable, these prefixes are not required but help to prevent any confusion with the standard built-in Windows Environment variables or any other command strings.
SET PATH… the command SET PATH is functionaly identical to the PATH command for modifying the user’s PATH variable, see the PATH page for more detail.
The CMD shell will fail to read an environment variable if it contains more than 8,191 characters.
SET is an internal command.
If Command Extensions are disabled all SET commands are disabled other than simple assignments like: _variable=MyText
Display a variable:
In most contexts, surround the variable name with %’s and the variable’s value will be used
e.g. To display the value of the _department variable with the
ECHO command:
ECHO %_department%If the variable name is not found in the current environment then SET will set %ERRORLEVEL% to 1 .
This can be detected using IF ERRORLEVEL …Including extra characters can be useful to show any white space:
ECHO [%_department%]
ECHO «%_department%«Type SET without parameters to display all the current environment variables.
Type SET with a variable name to display that variable
SET _departmentThe SET command invoked with a string (and no equal sign) will display a wildcard list of all matching variables
Display variables that begin with ‘P’:
SET p
Display variables that begin with an underscore
SET _
Set a variable:
Example of storing a text string:
C:\> SET «_dept=Sales and Marketing»
C:\> set _
_dept=Sales and MarketingSet a variable that contains a redirection character, note the position of the quotes which are not saved:
SET «_dept=Sales & Marketing»
One variable can be based on another, but this is not dynamic
E.g.C:\> set «xx=fish»
C:\> set «msg=%xx% chips»
C:\> set msg
msg=fish chipsC:\> set «xx=sausage»
C:\> set msg
msg=fish chipsC:\> set «msg=%xx% chips»
C:\> set msg
msg=sausage chipsAvoid starting variable names with a number, this will avoid the variable being mis-interpreted as a parameter
%123_myvar% < > %1 23_myvarTo display undocumented system variables:
SET «
Values with Spaces — using Double Quotes
There is no hard requirement to add quotation marks even when assigning a value that includes spaces:
SET _variable=one two three
ECHO %_variable%Adding quotation marks is a best practise and will account for any trailing spaces and special characters like ‘&’.
The variable contents will not include the surrounding quotes:SET «_variable=one & two«
ECHO «%_variable%»If you place quotation marks around just the value, then those quotes will be stored:
SET _variable=«one & two»
ECHO %_variable%This can be used for long filenames:
SET _QuotedPath=«H:\Config files\config 64.xml«
COPY %_QuotedPath% C:\Demo\final.xmlAlternatively you can add quotes at the point where they are needed:
SET «_Filename=config 64.xml»
COPY «H:\Config files\%_Filename%» C:\Demo\final.xml
Variable names with spaces
A variable can contain spaces and also the variable name itself can contain spaces,
therefore the following assignment:
SET _var =MyText
will create a variable called «_var « ← note the trailing space.
Prompt for user input
The /P switch allows you to set a variable equal to a line of input entered by the user.
The Prompt string is displayed before the user input is read.@echo off Set /P _ans=Please enter Department: || Set _ans=NothingChosen :: remove &’s and quotes from the answer (via string replace) Set _ans=%_ans:&=% Set _ans=%_ans:"=%
If "%_ans%"=="NothingChosen" goto sub_error
If /i "%_ans%"=="finance" goto sub_finance
If /i "%_ans%"=="hr" goto sub_hr goto:eof :sub_finance echo You chose the finance dept goto:eof :sub_hr echo You chose the hr dept
goto:eof :sub_error echo Nothing was chosenBoth the Prompt string and the answer provided can be left empty. If the user does not enter anything (just presses return) then the variable will be unchanged and the errorlevel will be set to 1.
The script above strips out any ‘&’ and » characters but may still break if the string provided contains both.
For user provided input, it is a good idea to fully sanitize any input string for potentially
problematic characters (unicode/smart quotes etc).The CHOICE command is an alternative for user input, CHOICE accepts only one character/keypress, when selecting from a limited set of options it will be faster to use.
Echo a string with no trailing CR/LF
The standard ECHO command will always add a CR/LF to the end of each string displayed, returning the cursor to the start of the next line.
SET /P does not do this, so it can be used to display a string. Feed a NUL character into SET /P like this, so it doesn’t wait for any user input:Set /P _scratch=»This is a message to the user » <nul
Place the first line of a file into a variable:
Set /P _MyVar=<MyFilename.txt
Echo %_MyVar%The second and any subsequent lines of text in the file will be discarded.
In very early versions of CMD, any carriage returns/new lines (CR+LF) before the first line containing text were ignored.
Delete a variable
Type SET with just the variable name and an equals sign:
SET _department=
Better still, to be sure there is no trailing space after the = place the expression in parentheses or quotes:
(SET _department=)
or
SET «_department=»
Arithmetic expressions (SET /a)
Placing expressions in «quotes» is optional for simple arithmetic but required for any expression using logical operators or parentheses.
A best practice is to use quotes around all SET /A expressions, then they will always be in place when needed.When referring to a variable in your expression, SET /A allows you to omit the %’s so _myvar instead of %_myvar%
The expression to be evaluated can include the following operators:
For the Modulus operator use (%) on the command line, or in a batch script it must be doubled up to (%%) as below.
This is to distinguish it from a FOR parameter.+ Add set /a "_num=_num+5" += Add variable set /a "_num+=5" - Subtract set /a "_num=_num-5" -= Subtract variable set /a "_num-=5" * Multiply set /a "_num=_num*5" *= Multiply variable set /a "_num*=5" / Divide set /a "_num=_num/5" /= Divide variable set /a "_num/=5" %% Modulus set /a "_num=17%%5" %%= Modulus set /a "_num%%=5" ! Logical negation 0 (FALSE) ⇨ 1 (TRUE) and any non-zero value (TRUE) ⇨ 0 (FALSE) ~ Bitwise invert & AND set /a "_num=5&3" 0101 AND 0011 = 0001 (decimal 1) &= AND variable set /a "_num&=3" | OR set /a "_num=5|3" 0101 OR 0011 = 0111 (decimal 7) |= OR variable set /a "_num|=3" ^ XOR set /a "_num=5^3" 0101 XOR 0011 = 0110 (decimal 6) ^= XOR variable set /a "_num=^3" << Left Shift. (sign bit ⇨ 0) An arithmetic shift. >> Right Shift. (Fills in the sign bit such that a negative number always remains negative.) Neither ShiftRight nor ShiftLeft will detect overflow. <<= Left Shift variable set /a "_num<<=2" >>= Right Shift variable set /a "_num>>=2" ( ) Parenthesis group expressions set /a "_num=(2+3)*5" , Commas separate expressions set /a "_num=2,_result=_num*5"Any SET /A calculation that returns a fractional result will be rounded down to the nearest whole integer.
Floating point arithmetic is not supported but you can call PowerShell for that: powershell.exe 12.9999999 + 2105001.01
or in a batch file:
For /F %%G in (‘powershell.exe 12.9999999 + 2105001.01’) do Echo Result: %%GIf a variable name is specified as part of the expression, but is not defined in the current environment, then SET /a will use a value of 0.
SET /A arithmetic shift operators do not detect overflow which can cause problems for any non-trivial math, e.g. the bitwise invert often incorrectly reverses the + / — sign of the result.
See SET /a examples below and this forum thread for more.
also see SetX, VarSearch and VarSubstring for more on variable manipulation.SET /A should work within the full range of 32 bit signed integer numbers (-2,147,483,648 through 2,147,483,647) but in practice for negative integers it will not go below -2,147,483,647 because the correct two’s complement result 2,147,483,648 would cause a positive overflow.
Examples
SET /A «_result=2+4»
(=6)SET /A «_result=5»
(=5)
SET /A «_result+=5″
(=10)SET /A «_result=2<<3″
(=16) { 2 Lsh 3 = binary 10 Lsh 3 = binary 10000 = decimal 16 }SET /A «_result=5%%2″
(=1) { 5/2 = 2 + 2 remainder 1 = 1 }SET /A «_var1=_var2=_var3=10»
(sets 3 variables to the same value — undocumented syntax.)SET /A will treat any character string in the expression
as an environment variable name. This allows you to do arithmetic with environment
variables without having to type any % signs to get the values. SET /A «_result=5 + _MyVar«Multiple calculations can be performed in one line, by separating each calculation with commas, for example:
Set «_year=1999»
Set /a «_century=_year/100, _next=_century+1»The numbers must all be within the range of 32 bit signed integer numbers (-2,147,483,648 through 2,147,483,647) to handle larger numbers use PowerShell or VBScript.
You can also store a math expression in a variable and substitute in different values, rather like a macro.
SET «_math=(#+6)*5»
SET /A _result=»%_math:#=4%
Echo %_result%
SET /A _result=»%_math:#=10%
Echo %_result%
Leading Zero will specify Octal
Numeric values are decimal numbers, unless prefixed by
0x for hexadecimal numbers,
0 for octal numbers.So 0x10 = 020 = 16 decimal
The octal notation can be confusing — all numeric values that start with zeros are treated as octal but 08 and 09 are not valid octal digits.
For example SET /a «_month=07» will return the value 7, but SET /a «_month=09» will return an error.
Permanent changes
Changes made using the SET command are NOT permanent, they apply to the current CMD prompt only and remain only until the CMD window is closed.
To permanently change a variable at the command line use SetX
or with the GUI: Control Panel ➞ System ➞ Environment ➞ System/User VariablesChanging a variable permanently with SetX will not affect any CMD prompt that is already open.
Only new CMD prompts will get the new setting.You can of course use SetX in conjunction with SET to change both at the same time:
Set _Library=T:\Library\
SetX _Library T:\Library\ /m
Change the environment for other sessions
Neither SET nor SetX will affect other CMD sessions that are already running on the machine. This as a good thing, particularly on multi-user machines, your scripts won’t have to contend with a dynamically changing environment while they are running.
It is possible to add permanent environment variables to the registry (HKCU\Environment), but this is an undocumented (and likely unsupported) technique and still it will not take effect until the users next login.
System environment variables can be found in the registry here:
HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
CALL SET
The CALL SET syntax will expand any variables passed on the same line, which is useful if you need to set one variable based on the value of another variable. CALL SET can also evaluate a variable substring, the CALL page has more detail on this technique, though in many cases a faster to execute solution is to use Setlocal EnableDelayedExpansion.
Autoexec.bat
Any SET statement in c:\autoexec.bat will be parsed at boot time
Variables set in this way are not available to 32 bit gui programs — they won’t appear in the control panel.
They will appear at the CMD prompt.If autoexec.bat CALLS any secondary batch files, the additional batch files will NOT be parsed at boot.
This behaviour can be useful on a dual boot PC.
Errorlevels
When CMD Command Extensions are enabled (the default):
Event Errorlevel If the variable was successfully changed. Errorlevel = unchanged, SET No variable found or invalid name.
SET _var=value when _var name starts with «/» and not enclosed in quotes.
SET /P Empty response from user.1 SET /A Unbalanced parentheses 1073750988 SET /A Missing operand 1073750989 SET /A Syntax error 1073750990 SET /A Invalid number 1073750991 SET /A Number larger than 32-bits 1073750992 SET /A Division by zero 1073750993 If the Errorlevel is unchanged, typically it will be 0 but if a previous command set an errorlevel, that will be preserved (this is a bug).
# I got my mind set on you
# I got my mind set on you… — Rudy Clark (James Ray/George Harrison)
Related commands
Syntax — VarSubstring Extract part of a variable (substring).
Syntax — VarSearch Search & replace part of a variable.
Syntax — Environment Variables — List of default variables.
CALL — Evaluate environment variables.
CHOICE — Accept keyboard input to a batch file.
ENDLOCAL — End localisation of environment changes, use to return values.
EXIT — Set a specific ERRORLEVEL.
PATH — Display or set a search path for executable files.
REG — Read or Set Registry values.
SETLOCAL — Begin localisation of environment variable changes.
SETX — Set an environment variable permanently.
Parameters — get a full or partial pathname from a command line variable.
StackOverflow — Storing a Newline in a variable.
Equivalent PowerShell: Set-Variable — Set a variable and a value (set/sv).
Equivalent PowerShell: Read-Host — Prompt for user input.
Equivalent bash command (Linux): env — Display, set, or remove environment variables.
Copyright © 1999-2025 SS64.com
Some rights reserved
Environment variables are not often seen directly when using Windows. However there are cases, especially when using the command line, that setting and updating environment variables is a necessity. In this series we talk about the various approaches we can take to set them. In this article we look at how to interface with environment variables using the Command Prompt and Windows PowerShell. We also note where in the registry the environment variables are set, if you needed to access them in such a fashion.
Print environment variables
You can use environment variables in the values of other environment variables. It is then helpful to be able to see what environment variables are set already. This is how you do it:
Command Prompt
List all environment variables
Command Prompt — C:\>
Output
1
2
3
4
5
6
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\user\AppData\Roaming
.
.
.
windir=C:\Windows
Print a particular environment variable:
Command Prompt — C:\>
Output
Windows PowerShell
List all environment variables
Windows PowerShell — PS C:\>
Output
1
2
3
4
5
6
7
8
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\user\AppData\Roaming
.
.
.
windir C:\Windows
Print a particular environment variable:
Windows PowerShell — PS C:\>
Output
Set Environment Variables
To set persistent environment variables at the command line, we will use setx.exe
. It became part of Windows as of Vista/Windows Server 2008. Prior to that, it was part of the Windows Resource Kit. If you need the Windows Resource Kit, see Resources at the bottom of the page.
setx.exe
does not set the environment variable in the current command prompt, but it will be available in subsequent command prompts.
User Variables
Command Prompt — C:\>
1
setx EC2_CERT "%USERPROFILE%\aws\cert.pem"
Open a new command prompt.
Command Prompt — C:\>
Output
1
C:\Users\user\aws\cert.pem
System Variables
To edit the system variables, you’ll need an administrative command prompt. See HowTo: Open an Administrator Command Prompt in Windows to see how.
Command Prompt — C:\>
1
setx EC2_HOME "%APPDATA%\aws\ec2-api-tools" /M
Warning This method is recommended for experienced users only.
The location of the user variables in the registry is: HKEY_CURRENT_USER\
. The location of the system variables in the registry is: HKEY_LOCAL_MACHINE\
.
When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.
One way is to get this message issued is to open the environment variables in the GUI, like we do in HowTo: Set an Environment Variable in Windows — GUI; we do not need to change anything, just open the Environment Variables
window where we can see the environment variables, then hit OK
.
Another way to get the message issued is to use setx
, this allows everything to be done on the command line, however requires setting at least one environment variable with setx
.
Printing Environment Variables
With Windows XP, the reg
tool allows for accessing the registry from the command line. We can use this to look at the environment variables. This will work the same way in the command prompt or in powershell. This technique will also show the unexpanded environment variables, unlike the approaches shown for the command prompt and for powershell.
First we’ll show the user variables:
Command Prompt — C:\>
1
reg query HKEY_CURRENT_USER\Environment
Output
1
2
3
HKEY_CURRENT_USER\Environment
TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp
TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp
We can show a specific environment variable by adding /v
then the name, in this case we’ll do TEMP
:
Command Prompt — C:\>
1
reg query HKEY_CURRENT_USER\Environment /v TEMP
Output
1
2
HKEY_CURRENT_USER\Environment
TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp
Now we’ll list the system environment variables:
Command Prompt — C:\>
1
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
ComSpec REG_EXPAND_SZ %SystemRoot%\system32\cmd.exe
FP_NO_HOST_CHECK REG_SZ NO
NUMBER_OF_PROCESSORS REG_SZ 8
OS REG_SZ Windows_NT
Path REG_EXPAND_SZ C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
PATHEXT REG_SZ .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE REG_SZ AMD64
PROCESSOR_IDENTIFIER REG_SZ Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
PROCESSOR_LEVEL REG_SZ 6
PROCESSOR_REVISION REG_SZ 3c03
PSModulePath REG_EXPAND_SZ %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Intel\
TEMP REG_EXPAND_SZ %SystemRoot%\TEMP
TMP REG_EXPAND_SZ %SystemRoot%\TEMP
USERNAME REG_SZ SYSTEM
windir REG_EXPAND_SZ %SystemRoot%
And same as with the user variables we can query a specific variable.
Command Prompt — C:\>
1
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH
Output
1
2
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
PATH REG_EXPAND_SZ C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
Unsetting a Variable
When setting environment variables on the command line, setx
should be used because then the environment variables will be propagated appropriately. However one notable thing setx
doesn’t do is unset environment variables. The reg
tool can take care of that, however another setx
command should be run afterwards to propagate the environment variables.
The layout for deleting a user variable is: reg delete HKEY_CURRENT_USER\
. If /f
had been left off, we would have been prompted: Delete the registry value EXAMPLE (Yes/No)?
. For this example we’ll delete the user variable USER_EXAMPLE
:
Command Prompt — C:\>
1
reg delete HKEY_CURRENT_USER\Environment /v USER_EXAMPLE /f
Output
1
The operation completed successfully.
Deleting a system variable requires administrator privileges. See HowTo: Open an Administrator Command Prompt in Windows to see how to do this.
The layout for deleting a system variable is: reg delete "HKEY_LOCAL_MACHINE\
. For this example we’ll delete the system variable SYSTEM_EXAMPLE
:
Command Prompt — C:\>
1
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v SYSTEM_EXAMPLE /f
If this was run as a normal user you’ll get:
Output
1
ERROR: Access is denied.
But run in an administrator shell will give us:
Output
1
The operation completed successfully.
Finally we’ll have to run a setx
command to propagate the environment variables. If there were other variables to set, we could just do that now. However if we were just interested in unsetting variables, we will need to have one variable left behind. In this case we’ll set a user variable named throwaway
with a value of trash
Command Prompt — C:\>
Output
1
SUCCESS: Specified value was saved.
Resources
- Windows XP Service Pack 2 Support Tools
- Windows Server 2003 Resource Kit Tools
- Reg — Edit Registry | Windows CMD | SS64.com
- Reg — Microsoft TechNet
- Registry Value Types (Windows) — Microsoft Windows Dev Center
- How to propagate environment variables to the system — Microsoft Support
- WM_SETTINGCHANGE message (Windows) — Microsoft Windows Dev Center
- Environment Variables (Windows) — Microsoft Windows Dev Center
Windows Server 2003 Resource Kit Tools will also work with Windows XP and Windows XP SP1; use Windows XP Service Pack 2 Support Tools with Windows XP SP2. Neither download is supported on 64-bit version.
Parts in this series
- HowTo: Set an Environment Variable in Windows
- HowTo: Set an Environment Variable in Windows — GUI
- HowTo: Set an Environment Variable in Windows — Command Line and Registry
Переменные окружения (среды) в Windows содержат различную информацию о настройках системы и среды пользователя. Различают переменные окружения пользователя, системы и процессов.
Самый простой способ просмотреть содержимое переменных окружения в Windows – открыть свойства системы (sysdm.cpl) -> Дополнительно -> Переменные среды. Как вы видите, в открывшемся есть две секции: в верхней содержатся переменные окружения пользователя, в нижнем – системные.
Кроме того, переменные среды хранятся в реестре системы. Пользовательские переменные хранятся в разделе HKEY_CURRENT_USER\Environment. Системные – в HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.
Вывести значения всех переменных окружения можно в командной строке Windows. Команда простая:
Set
Команда выведет список переменных среды и их значения.
В PowerShell для вывод всех переменных окружения можно использовать команду:
ls env:
Если нужно вывести значение только одной переменной, нужно воспользоваться командой echo, причем имя переменной нужно заключить в знаки процентов. Например,
Echo %systemroot%
Чтобы сохранить все переменные среды и их значения в текстовый файл, воспользуйтесь командой:
set > c:\tmp\env_var.txt
Переменные окружения конкретного процесса можно получить с помощью бесплатной утилиты Process Explorer (от Sysinternals). Достаточно открыть свойства процесса и перейти на вкладку Environment.