Экспорт переменных окружения windows

  • Windows equivalent of $export
  • How to export and import environment variables in windows?
  • How to export and import environment variables in windows?
  • HowTo: Set an Environment Variable in Windows — Command Line and Registry
  • Windows command line alternative for «export»
  • 2 ways to List environment variables in command line windows
  • Windows: List Environment Variables – CMD & PowerShell
  • How to Set Environment Variable in Windows

Windows equivalent of $export

People also askHow to create an environment variable in Windows?How to create
an environment variable in Windows?To Create a User Environment Variable in
Windows 10,

$ export PROJ_HOME=$HOME/proj/111
$ export PROJECT_BASEDIR=PROJ_HOME/exercises/ex1
$ mkdir -p $PROJ_HOME



SET PROJ_HOME=%USERPROFILE%/proj/111
SET PROJECT_BASEDIR=%PROJ_HOME%/exercises/ex1
mkdir "%PROJ_HOME%"

How to export and import environment variables in windows?

Add a comment. 127. I would use the SET command from the command prompt to
export all the variables, rather than just PATH as recommended above. C:\> SET
>> allvariables.txt. To import the variablies, one can use a simple loop: C:\>
for /F %A in (allvariables.txt) do SET %A. Share.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_CURRENT_USER\Environment



C:\> SET >> allvariables.txt



C:\> for /F %A in (allvariables.txt) do SET %A



regedit /e "%userprofile%\Desktop\my_user_env_variables.reg" "HKEY_CURRENT_USER\Environment"



set TODAY=%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%

regedit /e "%CD%\user_env_variables[%TODAY%].reg" "HKEY_CURRENT_USER\Environment"
regedit /e "%CD%\global_env_variables[%TODAY%].reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



global_env_variables[2017-02-14].reg
user_env_variables[2017-02-14].reg



C:\> PATH > path.txt



HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment



HKEY_CURRENT_USER\Environment



@echo off
:: RegEdit can only export into a single file at a time, so create two temporary files.
regedit /e "%CD%\environment-backup1.reg" "HKEY_CURRENT_USER\Environment"
regedit /e "%CD%\environment-backup2.reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

:: Concatenate into a single file and remove temporary files.
type "%CD%\environment-backup1.reg" "%CD%\environment-backup2.reg" > environment-backup.reg
del "%CD%\environment-backup1.reg"
del "%CD%\environment-backup2.reg"



gci env:* | sort-object name | Where-Object {$_.Name -like "MyApp*"} | Foreach {"[System.Environment]::SetEnvironmentVariable('$($_.Name)', '$($_.Value)', 'Machine')"}



# export_env.ps1
$Date = Get-Date
$DateStr = '{0:dd-MM-yyyy}' -f $Date

mkdir -Force $PWD\env_exports | Out-Null

regedit /e "$PWD\env_exports\user_env_variables[$DateStr].reg" "HKEY_CURRENT_USER\Environment"
regedit /e "$PWD\env_exports\global_env_variables[$DateStr].reg" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment">>SystemEnvVariablesSourceMachine.txt
reg query "HKEY_CURRENT_USER\Environment">>UserEnvVariablesSourceMachine.txt



(?:\A\r?\n|^HKEY_CURRENT_USER\\Environment\r?\n?|^HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\r?\n?|^\r?\n$|\r?\n\Z)



Literally Empty



^\s+(.*?)\s{4}\w+\s{4}(.*?)$



\1=\2



SystemEnvVariablesDestinationMachine.txt
UserEnvVariablesDestinationMachine.txt



SystemEnvVariablesFinalMerge.txt
UserEnvVariablesFinalMerge.txt



(^\w+=|.*?(?:;|$))



\1\n



(.)$\r?\n



\1



Get-Content .\UserEnvVariablesFinalMerge.txt | ForEach-Object {
    $envVarDataSplit = $($_).split("=")
    if($($envVarDataSplit).count -gt 0)
    {
        Write-Output "Key: $($envVarDataSplit[0]) ~ Value: $($envVarDataSplit[1])"
        SETX $envVarDataSplit[0] "$($envVarDataSplit[1])"
    }
}



Get-Content .\SystemEnvVariablesFinalMerge.txt | ForEach-Object {
    $envVarDataSplit = $($_).split("=")
    if($($envVarDataSplit).count -gt 0)
    {
        Write-Output "Key: $($envVarDataSplit[0]) ~ Value: $($envVarDataSplit[1])"
        SETX $envVarDataSplit[0] "$($envVarDataSplit[1])" /M
    }
}

How to export and import environment variables in windows?

The first set are system/global environment variables; the second set are
user-level variables. Edit as needed and then import the .reg files on the new
machine. I would use the SET command from the command prompt to export all the
variables, rather than just PATH as recommended above. C:\> SET >>
allvariables.txt

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

HKEY_CURRENT_USER\Environment



C:\> SET >> allvariables.txt



C:\> for /F %A in (allvariables.txt) do SET %A



regedit /e "%userprofile%\Desktop\my_user_env_variables.reg" "HKEY_CURRENT_USER\Environment"

HowTo: Set an Environment Variable in Windows — Command Line and Registry

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

1


set



1
2
3
4
5
6


ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\user\AppData\Roaming
.
.
.
windir=C:\Windows



1


echo %ProgramFiles%



1


C:\Program Files



1


Get-ChildItem Env:



1
2
3
4
5
6
7
8


Name                           Value
----                           -----
ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\user\AppData\Roaming
.
.
.
windir                         C:\Windows



1


echo $Env:ProgramFiles



1


C:\Program Files



1


setx EC2_CERT "%USERPROFILE%\aws\cert.pem"



1


echo %EC2_CERT%



1


C:\Users\user\aws\cert.pem



1


setx EC2_HOME "%APPDATA%\aws\ec2-api-tools" /M



1


reg query HKEY_CURRENT_USER\Environment



1
2
3


HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp



1


reg query HKEY_CURRENT_USER\Environment /v TEMP



1
2


HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp



1


reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"



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%



1


reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH



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\



1


reg delete HKEY_CURRENT_USER\Environment /v USER_EXAMPLE /f



1


The operation completed successfully.



1


reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v SYSTEM_EXAMPLE /f



1


ERROR: Access is denied.



1


The operation completed successfully.



1


setx throwaway trash



1


SUCCESS: Specified value was saved.

Windows command line alternative for «export»

Windows command line alternative for «export» Ask Question Asked 4 years, 4
months ago. Modified 2 years ago. Viewed 20k times 9 1. I’ve bought a book
about Machine Learning, and it needs an environment setup. windows command-
line environment-variables. Share. Improve this question. Follow edited Mar
30, 2018 at 14:02.

$ export ML_PATH="$HOME/ml"
$ mkdir -p $ML_PATH



SET ML_PATH="$HOME/ml"
SET mkdir $ML_PATH`

2 ways to List environment variables in command line windows

set command to get environment variable list. set command in windows used to
set the environment variables for command line scope. Syntax. set
VARIABLE=path/value. Here’s an example of setting JAVA HOME to the JDK route.
set JAVA_HOME=c:\JDK1.9. `SET command also lists all environment variables.
Here simple set command print all environment

set VARIABLE=path/value



set JAVA_HOME=c:\JDK1.9



C:\>set
ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=A:\android\sdk
ANT_HOME=A:\Java\apache-ant-1.10.0
APPDATA=C:\Users\Kiran\AppData\Roaming
ChocolateyInstall=C:\ProgramData\chocolatey
ChocolateyLastPathUpdate=132329753418192180
ChocolateyToolsLocation=C:\tools
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=KIRAN
ComSpec=C:\WINDOWS\system32\cmd.exe
DERBY_HOME=C:\db-derby-10.14.2.0-bin
DriverData=C:\Windows\System32\Drivers\DriverData
GOOGLE_API_KEY=no



set | more



C:\>set > output.txt



C:\>set derby
DERBY_HOME=C:\db-derby-10.14.2.0-bin



Get-ChildItem Env:

Windows: List Environment Variables – CMD & PowerShell

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

C:\> set


C:\> echo %ENVIRONMENT_VARIABLE%


PS C:\> gci env:* | sort-object name


PS C:\> echo $env:ENVIRONMENT_VARIABLE

How to Set Environment Variable in Windows

Set Environment Variable in Windows via GUI. Follow the steps to set
environment variables using the Windows GUI: 1. Press Windows + R to open the
Windows Run prompt. 2. Type in sysdm.cpl and click OK. 3. Open the Advanced
tab and click on the Environment Variables button in the System Properties
window. 4.

set


Get-ChildItem Env:


echo %[variable_name]%


echo $Env:[variable_name]


setx [variable_name] "[variable_value]"


setx Test_variable "Variable value"


setx [variable_name] "[variable_value]" /M


reg query HKEY_CURRENT_USEREnvironment


reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment"


reg query HKEY_CURRENT_USEREnvironment /v [variable_name]


reg query "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name]


reg delete HKEY_CURRENT_USEREnvironment /v [variable_name] /f


reg delete "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment" /v [variable_name] /f


setx [variable_name] trash

С помощью PowerShell вы можете получать, добавлять, удалять, или изменять значения переменных окружения (среды). В переменных окружения Windows хранит различную пользовательскую и системную информацию (чаще всего это пути к системным и временным папкам), которая используется операционной системой и приложениями, установленными на компьютере.

В Windows доступны несколько типов переменных окружения:

  • Переменные окружения процесса – создаются динамически и доступны только в текущем запущенном процесс
  • Пользовательские переменные окружения – содержат настройки конкретного пользователя и хранятся в его профиле (хранятся в ветке реестре
    HKEY_CURRENT_USER\Environment
    )
  • Системные переменные окружения – глобальные переменные окружения, которые применяются для все пользователей (хранятся в ветке
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    )

    Переменные окружения хранятся в реестре Windows

Типы переменных окружения Windows указаны в порядке уменьшения приоритета. Т.е. значение переменной окружения %TEMP% в пользовательском профиле будет иметь больший приоритет, чем значение системной переменной окружения %TEMP%.

Для управления переменными окружениями обычно используется вкладка Advanced в свойствах системы. Чтобы открыть System Properties, выполните команду
SystemPropertiesAdvanced
и нажмите на кнопку Environment Variable.

В этом окне можно создать и отредактировать переменные среды для текущего пользователя или системные переменные окружения.

Настройка переменных окружения в окне свойств системы

Чтобы вывести полный список переменных окружения и их значения в PowerShell, выполните команду:

Get-ChildItem Env:

PowerShell - вывести все переменные окружения

Как вы видите, для доступа к переменным окружения в PowerShell используется отдельный виртуальный диск Env:, доступный через провайдер Environment.

Виртуальный диск с переменными окружения

Получить значение определенной переменной окружения Path:

Get-ChildItem env:Path

Получить значение переменной окружения из PowerShell

Т.к. переменные окружения, по сути, это файлы на виртуальном диске, нажатием кнопки TAB вы можете использовать автозавершение для набора имени переменной окружения.

Чтобы разбить значение переменной окружения на строки, выполните:

(Get-ChildItem env:Path).value -split ";"

Разбить значение переменной окружения на строки

Добавить значение в переменную окружения Path:

$Env:Path += ";c:\tools"

Однако это добавляет временное значение в переменную окружения
Path
. При следующей перезагрузке новое значение в переменной будет сброшено. Чтобы добавить постоянное значение в системную переменную окружения, используется такая конструкция:

$path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
[System.Environment]::SetEnvironmentVariable("Path", $path + ";C:\tools", "Machine")
[System.Environment]::GetEnvironmentVariable("Path","Machine") -Split ";"

Чтобы изменить пользовательскую переменную окружения, замените в предыдущих командах область Machine на User.

Несмотря на то, что фактически переменные окружения и их значения хранятся в реестре, прямое изменение их значений в реестре используется редко. Причина в том, что текущий процесс при запуске считывает значение переменных окружения из реестра. Если вы измените их, процесс не будет уведомлён об этом.

Если вам нужно из PowerShell изменить в реестре значение переменной окружения, используются команды:

$variable = Get-ItemPropertyValue -Path 'HKCU:\Environment\' -Name 'Path'
$add_path = $variable + ';C:\Git\'
Set-ItemProperty -Path 'HKCU:\Environment\' -Name 'Path' -Value $add_path

Вы можете создать локальную переменную окружения. По умолчанию такая переменная окружения будет доступна только в текущем процессе (PowerShell), из которого она создана. После того, как процесс будет закрыт – переменная окружения будет удалена.

$env:SiteName = 'winitpro.ru'
Get-ChildItem Env:SiteName

Если нужно создать глобальную системную переменную (нужны права администратора), используйте команду:

[System.Environment]::SetEnvironmentVariable('siteName','winitpro.ru',"Machine")

Очистить и удалить глобальную переменную окружения:

[Environment]::SetEnvironmentVariable('siteName', $null, "Machine")

  • 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:

  1. Machine
  2. User
  3. 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.

Using an environment variable

You can also edit this variable to include a sub-directory of the path, like opening the user account’s desktop by typing in “%HOMEPATH%\Desktop%”.

Using an environment variable to open its subdirectory

What are Environment Variable Scopes

As we mentioned earlier, there are 3 scopes for environment variables: Machine/System, user, and process. These scopes define the limitations of the variables and where they can be used.

Below you’ll find a more detailed explanation of the different types of environment variable scopes.

System/Machine

The environment variables defined inside this scope can be used by anyone on the system. These types of variables are associated with the running instance of Windows. Any user account can read these, set, change, or delete them, provided they have administrative rights.

User

The environment variables defined within this scope are only user-specific and might be different for each user account. This is associated with the current user. User variables overwrite machine-scoped variables with the same name.

Process

Environment variables in this scope are a combination of machine and user scopes in addition to some dynamically created variables by the Windows OS.

Now that you know what environment variables are and how they work, let us see which variables are available in a Windows OS.

Here is a list of the process variables which are available in this scope:

  • 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:

Windows Environment Variables Opt

Default Windows Environment Variables
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
List of all Windows Environment Variables

Where are Environment Variables Stored

The environment variables are stored in 2 places in the Windows Registry; one for the system and one for individual users.

The system environment variables are stored at the following location:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
System environmental variables in Windows Registry

System environment variables in Windows Registry

The user environment variables are stored at the following location:

Computer\HKEY_CURRENT_USER\Environment
User environmental variables in Windows Registry

User environment variables in Windows Registry

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:

  1. Navigate to the following:

    Settings app >> System >> About
  2. Now click Device Specifications to expand it.

    Expand Device Specifications

    Expand Device Specifications
  3. Now click Advanced system settings under Related links.

    Open Advanced system settings

    Open Advanced system settings
  4. From the pop-up System Properties window, switch to the Advanced tab, and then click Environment Variables.

    Open Environmental Variables

    Open Environment Variables
  5. 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.

    Environmental Variables window

    Environment Variables window

View Environment Variables from Command Line

If you want to access the environment variables using the Command Line, here is how:

  1. 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
  2. From the pop-up System Properties window, switch to the Advanced tab, and then click Environment Variables.

    Open Environmental Variables2

    Open Environment Variables
  3. 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.

    Environmental Variables window2

    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 environmental variables in PowerShell

List environment variables in PowerShell

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 all environment variables in Command Prompt

View all environment variables in Command Prompt

View Value for Environment Variable using Command Prompt

If you access the environment variable using any of the given methods above, then you can see their values as well. Another method to view the value of an environment variable is through the Command Prompt.

Simply type in “echo” followed by the environment variable name in the “%” sign in an elevated Command Prompt and you will then see its value(s), as in this image:

Display environment variable value

Display environment variable value

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:

  1. 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 varibale

    Create a new variable
  2. In the popup window, set a name for the variable and then enter its value. Once done, click OK.

    Enter details for variable

    Enter details for variable
  3. 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.

Access path using an environment variable

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]
Create new environment variable using Command Prompt

Create new environment variable using Command Prompt

Permanent Environment Variable

If you want to create a permanent environment variable, then use this cmdlet instead:

Setx [VariableName] "[Value]"
Permanent variable created using Command Prompt

Permanent variable created using Command Prompt

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

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

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

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.

  1. Access the Environment Variables window using one of the given methods above.

  2. In the Environment Variables window, click on the variable that you want to remove and click Delete under the same section.

    Delete environmental variable

    Delete environment variable
  3. 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:

  1. Access the Environment Variables window using one of the given methods above.

  2. Here, click on the variable that you want to edit and then click Edit under the same section.

    Edit an environmental variable

    Edit an environment variable
  3. 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

    Edit variable details
  4. 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:
Enter the Env drive

Enter the Env: drive

To get the complete list of environment variables and their values, use the following cmdlet:

Get-Item -Path Env:
Get complete list of variables in Env

Get the complete list of variables in 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]
Create a new variable in Env drive

Create a new variable in Env: drive

To set the value of an existing variable, use this cmdlet:

Set-Item -Path Env:[VariableName] -Value "[Value]"
Set change variable value in Env drive

Set/change variable value in Env drive

To delete an environment variable from the Env: drive, use this cmdlet:

Remove-Item -Path Env:\[VariableName]
Delete variable in Env Drive

Delete variable in Env Drive

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.

  • SS64
  • CMD
  • How-to

Environment variables are mainly used within batch files, they can be created,
modified and deleted for a session using the SET command. To make permanent changes, use SETX

Variables can be displayed using either SET or
ECHO.

Variables have a percent sign on both sides: %ThisIsAVariable%
The variable name can include spaces, punctuation and mixed case: %_Another Ex.ample%
(This is unlike Parameter variables which only have one % sign and are always one character long: %A )

Most used variables:

%AppData% — C:\Users\{username}\AppData\Roaming
%AppData%\Microsoft\Windows\Start Menu\ ― Windows Start menu shortcuts
%LocalAppData% ― C:\Users\{username}\AppData\Local
%Temp% ― C:\Users\{Username}\AppData\Local\Temp
%SystemRoot% ― C:\Windows
%AllUsersProfile% ― C:\ProgramData
%UserProfile% ― C:\Users\{username}

A variable name may include any of the following characters:
A-Z, a-z, 0-9, # $ ‘ ( ) * + , — . ? @ [ ] _ ` { } ~
The first character of the name must not be numeric.

Standard (built-in) Variables

Variable Dynamic (update as used) Volatile (Set at Logon) Shell Variable User Environment Variable
(SETX)
System Environment Variable
(SETX /M)
Default value assuming the system drive is C:
ALLUSERSPROFILE     Y     C:\ProgramData
Predefined machine-wide system variable.
APPDATA   Y Y     C:\Users\{username}\AppData\Roaming
CD Y   Y     The current directory (string).
ClientName   Y Y     Terminal servers only — the ComputerName of a remote host.
CMDEXTVERSION Y   Y     The current Command Processor Extensions version number.
(NT = «1», Win2000+ = «2».)
CMDCMDLINE Y   Y     The original command line that invoked the Command Processor.
CommonProgramFiles     Y     C:\Program Files\Common Files
COMMONPROGRAMFILES(x86)     Y     C:\Program Files (x86)\Common Files
COMPUTERNAME     Y     {computername}
COMSPEC         Y C:\Windows\System32\cmd.exe or if running a 32 bit WOW — C:\Windows\SysWOW64\cmd.exe
Comspec is used whenever the command shell spawns a new process, e.g. the FOR command, if comspec is not defined those processes will fail to launch.
DATE Y   Y     The current date using same region specific format as DATE.
ERRORLEVEL Y   Y     The current ERRORLEVEL value, automatically set when a program exits.
FPS_BROWSER_APP_PROFILE_STRING
FPS_BROWSER_USER_PROFILE_STRING
    Y     Internet Explorer
Default
These are undocumented variables for the Edge browser in
Windows 10.
HighestNumaNodeNumber Y (hidden)   Y     The highest NUMA node number on this computer.
HOMEDRIVE   Y Y     C:
HOMEPATH   Y Y     \Users\{username}
HOMESHARE   Y       Network home folder.
LOCALAPPDATA   Y Y     C:\Users\{username}\AppData\Local
LOGONSERVER   Y Y     \\{domain_logon_server}
NUMBER_OF_PROCESSORS         Y The Number of processors running on the machine.
OneDrive       Y   OneDrive synchronisation folder.
Typically C:\users\%username%\OneDrive
If only a single OneDrive client is installed then use %OneDrive%.
OneDriveCommercial       Y   OneDrive for Organizations’ synchronisation folder (if installed).
Typically C:\users\%username%\OneDrive
OneDriveConsumer       Y   OneDrive Personal synchronisation folder.
Typically C:\users\%username%\OneDrive
OS         Y Operating system on the user’s workstation.
PATH       Y Y C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem;{plus program paths}
PATHEXT       Y .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH; .MSC
Determine the default executable file extensions to search for and use, and in which order, left to right.
The syntax is like the PATH variable — semicolon separators.
PROCESSOR_ARCHITECTURE         Y AMD64/IA64/x86 This doesn’t tell you the architecture of the processor but only of the current process, so it returns «x86» for a 32 bit WOW process running on 64 bit Windows. See detecting OS 32/64 bit
PROCESSOR_ARCHITEW6432           =%PROCESSOR_ARCHITECTURE% (but only available to 64 bit processes)
PROCESSOR_IDENTIFIER         Y Processor ID of the user’s workstation.
PROCESSOR_LEVEL         Y Processor level of the user’s workstation.
PROCESSOR_REVISION         Y Processor version of the user’s workstation.
ProgramData     Y     C:\ProgramData
ProgramFiles     Y     C:\Program Files or C:\Program Files (x86)
ProgramFiles(x86) 1     Y     C:\Program Files (x86)   (but only available when running under a 64 bit OS)
ProgramW6432           =%ProgramFiles%(but only available when running under a 64 bit OS)
PROMPT     Y     Code for current command prompt format,usually $P$G
C:>
PSModulePath         Y %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
Public     Y     C:\Users\Public
RANDOM Y         A random integer number, anything from 0 to 32,767 (inclusive).
%SessionName%           Terminal servers only — for a terminal server session, SessionName is a combination of the connection name, followed by #SessionNumber. For a console session, SessionName returns «Console».
SYSTEMDRIVE     Y     C:
SYSTEMROOT     Y     The main Windows system folder. By default, C:\Windows
Windows can be installed to a different drive letter or (rarely) a different folder.
systemroot is a predefined machine-wide read-only system variable that will resolve to the correct location.
Defaults in early Windows versions are C:\WINNT, C:\WINNT35 and C:\WTSRV
TEMP and TMP       Y Y C:\Users\{Username}\AppData\Local\Temp
Under XP this was \{username}\Local Settings\Temp
TIME Y         The current time using same format as TIME. In some locales, this will include a comma separator which is also a command delimiter.
UserDnsDomain   Y   Y   Set if a user is a logged on to a domain and returns the fully qualified DNS domain that the currently logged on user’s account belongs to.
USERDOMAIN   Y Y     {userdomain}
USERDOMAIN_roamingprofile   Y       The user domain for RDS or standard roaming profile paths. Windows 8/10/2012.
USERNAME   Y     Y Defined as «SYSTEM», resolves as {username}
USERPROFILE   Y Y     %SystemDrive%\Users\{username}
This is equivalent to the $HOME environment variable in Unix/Linux
WINDIR         Y Set by default as windir=%SystemRoot%
%WinDir% pre-dates Windows NT, its use in many places has been replaced by the system variable: %SystemRoot%
ZES_ENABLE_SYSMAN           1
System Resource Management library, Windows 11. Enables driver initialization and dependencies for system management. Set to 0 to disable.

1 Only on 64 bit systems, is used to store 32 bit programs.

To scroll this page, press [ a – z ] on the keyboard, or ‘\‘ to Search.

Dynamic environment variables are computed each time the variable is expanded, this makes them inherently read-only.
When all variables are listed with SET, these will not appear in the list. Dynamic variables are internal to cmd.exe, meaning they are available only within a cmd.exe command prompt window (either an interactive process or a batch file). They are not available to other executables or other scripting languages.

Volatile variables are defined under the registry: HKCU\Volatile Environment
Do not attempt to directly SET a volatile variable, while you could change them, the system will overwrite them with newly derived values. The majority of volatile variables are CMD shell variables, so like all CMD shell variables they are stored in memory only.

Environment variables are stored in the registry:

User Environment Variables: HKCU\Environment
System Environment Variables: HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

By default, files stored under Local Settings do not roam with a roaming profile.

Example

Get the full pathname of a file in Program Files, this will return the correct result even on machines which have Program Files on a different drive:

   For /f "delims=" %%G in ('dir /s /b "%ProgramFiles%\demo.exe"') Do set _filename="%%G"
Echo %_filename%

Precedence

When a new process is started, the variables will be loaded in the following order:

      1. System Environment Variables
      2. Shell Variables (per user)
      3. User Environment Variables
      4. Shell Variables (other)

After the process has started, additional shell variables can be defined with SET, these will be available only to the current CMD shell session, but they will take precedence over any environment variables with the same name.

For example, if the SET command is used to modify the PATH, or if it is removed completely with PATH ; that will affect the current process, but not any other programs or CMD sessions opened before or after the current one.

This precedence is important to understand because if you try to set a System Environment variable PATH = %APPDATA%;C:\Windows, it will fail because the %APPDATA% Shell variable is not created until after the System environment variables are imported to the session.
However, you can use %APPDATA% to build a User environment variable PATH.

Running the SET command with no options will display all Shell variables plus all User and System Environment variables, in other words every variable available to be read by that session. In PowerShell the same list is available via the env: drive

Undocumented Dynamic variables (read only)

%__APPDIR__%   The directory path to the current application .exe, terminated with a trailing backslash. (Global) — discuss
%__CD__%   The current directory, terminated with a trailing backslash. (Global)
%=C:%   The current directory of the C: drive. ( See Raymond Chen’s explanation of this.)
%=D:%   The current directory of the D: drive if drive D: has been accessed in the current CMD session.
%DPATH%   Related to the (deprecated) DPATH command.
%=ExitCode%   The most recent exit code returned by an external command, such as CMD /C EXIT n, converted to hex.
%=ExitCodeAscii%   The most recent exit code returned by an external command, as ASCII.
(Values 0-32 do not display because those map to ASCII control codes.)
%FIRMWARE_TYPE% The boot type of the system: Legacy, UEFI, Not implemented, Unknown Windows 8/2012.
%KEYS%   Related to the (deprecated) KEYS command.

It is impossible to use SET to define or alter these variables because SET does not allow ‘=’ in a variable name.
More detail on these undocumented variables can be found in this stackoverflow answer from Dave Benham.

Undocumented Dynamic variables (read/write)

%__COMPAT_LAYER%   Set the ExecutionLevel to either RunAsInvoker (asInvoker), RunAsHighest(highestAvailable) or RunAsAdmin(requireAdministrator) for more see elevation and Q286705 (Win XP) / Application Compatibility Toolkit for other Compatibility Layers (colours,themes etc).

Pass variables between batch scripts

There are several ways to pass values between batch files, or between a batch file and the command line, see the CALL and SETLOCAL pages for full details.

A child process by default inherits a copy of all environment variables from its parent, this makes environment variables unsuitable for storing secret information such as API keys or user passwords, especially in rare occasions like crashes where a crash log will often include the full OS environment at the time of the crash. PowerShell/Get-Credential is a more secure approach.

If Command Extensions are disabled, the following dynamic variables will be not accessible:
%CD% %DATE% %TIME% %RANDOM% %ERRORLEVEL% %CMDEXTVERSION% %CMDCMDLINE% %HIGHESTNUMANODENUMBER%

“Men may be convinced, but they cannot be pleased against their will. But though taste is obstinate, it is very variable, and time often prevails when arguments have failed” ~ Samuel Johnson

Related commands

How-to: Array Variables in CMD.
How-to: User Shell Folders — Profile, Start Menu — Location of user profile folders.
How-to: Detecting 32 vs 64 bit Windows.
CALL — Evaluate environment variables.
SET — View environment variables, set local variables.
SETX — Set environment variables.
How the environment-building process works — Raymond Chen [MSFT].
Wikipedia: Environment Variables.
PowerShell equivalent: Working with Environment variables.
Q100843 — The four types of environment variable.
Q286705 — Set compatibility variables in a batch file.
Q242557 — Registry Settings for Folder Redirection.
StackOverflow — Storing a Newline in a variable.


Copyright © 1999-2025 SS64.com
Some rights reserved

Environment variables are user variables or Windows system variables that describe the environment in which apps run. They can tell your apps things like the name of the computer, the name of the user account, the current working directory, etc. Do you want to know more about how to use environment user variables and Windows system variables? If you do, read this tutorial and learn how to create environment variables in Windows 11 and Windows 10. There are some situations when knowing how to do that can prove very useful.

Things you should know before creating environment variables in Windows

There are two things you should know before following any of the steps shown in this guide to create user and system variables pointing to a folder, file, or anything else. The first and the most important one is to understand what environment variables are. Secondly, you should know the differences in user variables vs. system variables in order to be able to decide what kind of variable you should create. For answers and explanations on these matters, I recommend you read this article before going ahead with the instructions below: What are environment variables in Windows?.

Environment user and system variables in Windows

Environment user and system variables in Windows

Then, once you understand what environment variables are and once you know what type of variable you want to create, you’ll have to open the Environment Variables window. If you’ve read the tutorial I recommended in the previous paragraph, you already know how to do it. However, if you didn’t have time for that, know that an easy method of launching the Environment Variables is to use the search.

If you’re using Windows 11, click or tap the search box (or button) on your taskbar, type environment, and click or tap the “Edit the system environment variables” result.

How to open the Environment Variables in Windows 11

How to open the Environment Variables in Windows 11

The same applies to Windows 10. Click or tap on the search box on the taskbar, enter environment in the search box, and select “Edit the system environment variables” in the list of results.

How to open the Environment Variables in Windows 10

How to open the Environment Variables in Windows 10

Then, the steps to create user variables or system variables are the same regardless of the operating system you’re using. As you can see in the next picture, even the Environment Variables window is identical in Windows 11 and Windows 10.

Environment Variables in Windows 11 vs Windows 10

Environment Variables in Windows 11 vs Windows 10

Without further ado, here are the steps to create environment user variables and system variables in Windows:

How to create environment user variables in Windows

User environment variables are available only to your user account. When creating such variables, their values should include paths towards locations that are accessible to your user account. For example, you can’t have your user variable point to a personal folder of another user account (like Documents, Pictures, Music, etc.). In the “User variables for [user account]” section, click or tap New.

The Environment Variables window

The Environment Variables window

The “New User Variable” window opens. Start by typing the name of the variable you want to create (1). Make it something suggestive to easily remember its purpose. Then, type its value (2). The value may include a path or more. A path can point to a folder or a file. You can also use other existing variables to build up the path you want. For example, if you want the variable to point to the folder used by Steam to save your games, you can set its value like this:

%programfiles(x86)%\Steam\steamapps\common

Entering the name and value of a new user variable

Entering the name and value of a new user variable

TIP: If you want your environment user variable to have more than one value, separate its values with semicolons (;) — for example, Path 1; Path 2; Path 3. Oh, and it’s not mandatory to use only paths to folders and files as values for user variables. Depending on what you want to do with the variable you create, you can also store strings (text) as its value.

When you are done setting the user variable, click or tap OK. The new variable is added to the list of user variables, but it is not yet created, so you can’t use it at this time.

The new user variable has been added to the list

The new user variable has been added to the list

To create the new user variable, click or tap OK in the Environment Variables window.

Saving the new user variable in Windows

Saving the new user variable in Windows

To test if the user variable was created successfully and that it points to what you want, open a Run window (Windows + R). Type the name of the environment variable you just created between percent (%) signs. For example, to execute the steamgames variable that I just created, I have to type:

%steamgames%

Then, click or tap on OK. In my case, this action opens the folder that contains all the games I have downloaded and installed from my Steam account.

Checking a user variable in Windows

Checking a user variable in Windows

IMPORTANT: Any user can add, change, or delete user environment variables. User variables can be created by Windows 11 or Windows 10, apps, and users alike.

How to create Windows system variables

The process for creating system variables is the same as for creating user variables. To make sure you get it right, I’ll go through another quick example.

In the System variables section from the Environment Variables window, click or tap New.

Starting the process of creating a new Windows system variable

Starting the process of creating a new Windows system variable

The New System Variable window opens. Enter the variable’s name (1) and value (2). In the next screenshot, for instance, you can see that I chose to create a new system variable called games that points to a folder called Games on my C: drive.

Entering the name and value of a New System Variable

Entering the name and value of a New System Variable

TIP: Note that you can add multiple values to a variable — all you need to do is separate them with semicolons (;). Also, keep in mind that if you specify a path as a value for a system variable, that path should be accessible to all user accounts. If that path points to a location where only one user account has access, you should create a user variable instead of a system variable.

When you are done customizing the new system variable, click or tap OK. The new variable is added to the list of system variables, but it is not yet created.

The Windows system variable has been added to the list

The Windows system variable has been added to the list

In the Environment Variables window, click or tap OK to create the new environment variable.

Saving a new Windows system variable

Saving a new Windows system variable

To test if the system variable was created successfully, open Run (Windows + R) and insert the name of the environment system variable you created between percent (%) signs. For example, to run the games variable that I created, I must type:

%games%

Then, press the OK button.

Verifying a Windows system variable

Verifying a Windows system variable

In my case, Windows opened the Games folder where I keep most of my games. All users have access to this folder, and they can use this variable to access those games quickly.

IMPORTANT: Are you wondering whether any user can add system environment variables or change existing ones’ values? The answer is NO! Only administrators can perform these actions. Standard users don’t have enough clearance to make or change Windows system variables because they affect every user and every app on the PC. If you’re using Windows 11, this tutorial provides more details about standard and administrator accounts: How to change the Administrator account on Windows 11. And, if you have Windows 10, read this guide instead: 6 ways to change an account to Administrator and back in Windows 10.

What user variables or Windows system variables did you create?

The process involved in creating environment variables in Windows is not that complicated. Furthermore, it’s the same in Windows 11 and Windows 10. However, before you get the hang of it, you should first experiment by making a couple of safe user variables that don’t negatively impact the system’s proper operation. If you have questions about environment variables or if you have something to add to this guide, don’t hesitate to leave me a comment. Also, if you want to receive news whenever we publish new articles, do subscribe to our newsletter using the form below.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Ubuntu для windows удалить
  • Cpu scheduling windows 10
  • Alc892 driver windows 10
  • Исходный код ядра windows
  • Pink theme for windows 10