To set a temporary or 'per session' environment varible from a command line you can use:

set ‹var name›=‹value>

Make sure your spacing is exactly as shown above, if you add a space between the equal sign the command will fail.

Check: Link for a nice tutorial and info on environment variables.

Answer from akseli on Stack Exchange
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows-server › administration › windows-commands › set_1
set (environment variable) - Windows commands
If you use the set command without any parameters, the current environment settings are displayed. These settings usually include the COMSPEC and PATH environment variables, which are used to help find programs on disk. Two other environment variables used by Windows are PROMPT and DIRCMD.
Discussions

windows - Set a persistent environment variable from cmd.exe - Stack Overflow
I have to set environment variables on different windows machines, but I don't want to be bothered changing them manually by getting on the properties screen of "My Computer" I want to do... More on stackoverflow.com
🌐 stackoverflow.com
command line - Set Environment Variables Windows - Stack Overflow
First off, I'd like to apologise if this has already been covered. It's difficult to filter through all the existing issues similar to this one. So in Windows there is two (as far as I'm aware) wa... More on stackoverflow.com
🌐 stackoverflow.com
Set windows environment variables with a batch file - Stack Overflow
I was looking for a way to set the environment path variable with a .cmd file. When the path variable was getting too long, I got some errors. Just add the needed variables to 'Set Path variable' b... More on stackoverflow.com
🌐 stackoverflow.com
Windows Environment Variables
Does these links help U..? powershell method in cmd More on reddit.com
🌐 r/techsupport
2
1
September 20, 2022
People also ask

How Do I Find Environment Variables in Windows 10?

To find environment variables in Windows 10, you can follow the steps described above to find the environment variable information tucked away inside the system's advanced settings.

Alternatively, if you just need to see what the variables are but don't need to change them, you can simply open a command-line interface by hitting Ctrl +Esc and typing "cmd" in the command box, then type "set" in the command window. This prints out all the environment variables that are set on your system.

🌐
alphr.com
alphr.com › home › how to set environment variables in windows 10
How to Set Environment Variables in Windows 10
Why Can't I Edit the Environment Variables?

There are several reasons that you may not be able to set these variables.

1. The first of your problems could be that you don't have Admin rights. To set or edit this function, you must be the Administrator of the system.

2. If you are the Admin, yet the edit function is greyed out, try accessing the Environment Variables by accessing the Control Panel from the Start menu. Click on Advanced System Settings, then click Environment Variables.

🌐
alphr.com
alphr.com › home › how to set environment variables in windows 10
How to Set Environment Variables in Windows 10
🌐
Computer Hope
computerhope.com › issues › ch000549.htm
How to Set the Path and Environment Variables in Windows
After creating or modifying the environment variables, restart the computer for those changes to take effect in Windows. ... You can edit other environment variables by highlighting the variable in the System variables section and clicking Edit. If you need to create a new environment variable, click New, and enter the variable name and value. ... To view and set the path through the Windows command line, use the path command.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to set environment variable in windows
How to Set Environment Variables in Windows
December 9, 2025 - The method for checking current environment variables depends on whether you are using the Command Prompt or Windows PowerShell: In the Command Prompt, use the following command to list all environment variables: ... Both the Command Prompt and PowerShell use the echo command to list specific environment variables. ... Here, [variable_name] is the name of the environment variable you want to check. Follow the steps to set environment variables using the Windows GUI:
Top answer
1 of 9
179

Note: After seeing lots of comments about setting environment variables without administrator rights in Windows 10, I think I have found a way. I was not administrator and could use PowerShell.

PowerShell method

You can list all environment variables with: Get-ChildItem Env:.

To get the value of a specific variable: $Env:PATH, where PATH is the name of the variable.

To set a variable: [Environment]::SetEnvironmentVariable("PATH", "C:\TestPath", "User"), the first parameter is the name of the variable, the second is the value, the third is the level of.

There are different ways to work with environment variables and certain quirks with them in PowerShell so consult the link for details.

Old method (no longer available in newer Windows 10 updates, use PowerShell or see other answers)

Go into Settings and click on System.

Then on the left side click About and select System info at the bottom.

In the new Control Panel window that opens, click Advanced system settings on the left.

Now in the new window that comes up, select Environment Variables... at the bottom.

2 of 9
127

Still the same as ever: It’s in the old-style control panel’s “System” thingy. You can reach it with WinBreak or by right-clicking the Start button.

From there, select “Advanced system settings” → “Environment Variables”.

Or you can do it the hard way and find some other entry point to the old-style control panel, like the Network and Sharing Center or the Desktop folder(!).

Find elsewhere
🌐
SS64
ss64.com › nt › set.html
Set - Environment Variable command - Windows CMD
If Command Extensions are disabled all SET commands are disabled other than simple assignments like: _variable=MyText · 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 .
🌐
Alphr
alphr.com › home › how to set environment variables in windows 10
How to Set Environment Variables in Windows 10
October 15, 2022 - A dialog box will pop up, allowing you to enter a new variable name and to set its initial value: New adds a new environment variable. Edit lets you edit whatever environment variable you have selected. Delete lets you delete the selected environment variable. Save any changes that you make by clicking OK. Under the Environment Variables window, choose or highlight the PATH variable in the System Variables section shown in the window.
🌐
Twilio
twilio.com › en-us › blog › how-to-set-environment-variables-html
How to Set Environment Variables | Twilio
December 9, 2025 - New-Item -Path Env:\TWILIO_ACCOUNT_SID -Value '<YOUR_ACCOUNT_SID>' [Environment]::SetEnvironmentVariable('TWILIO_ACCOUNT_SID', '<YOUR_ACCOUNT_SID>') [Environment]::SetEnvironmentVariable('TWILIO_ACCOUNT_SID', '<YOUR_ACCOUNT_SID>', 'Process') To persist environment variables across shell instances, you can save the cmdlets into your profile script, or on Windows, you can save them in the user registry or machine registry like this:
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_environment_variables
about_Environment_Variables - PowerShell | Microsoft Learn
For more information on profiles, see about_Profiles. On Windows, you can specify a scope for the SetEnvironmentVariable() method as the third parameter to set the environment variable in that scope.
🌐
Progress
docs.progress.com › bundle › openedge-sql-development › page › Set-environment-variables-in-Windows.html
Set environment variables in Windows
Work from the Settings menu of your Windows environment to set your JDBC driver environment variables. To set the environment variable in Windows: Select Start > Settings > Control Panel > System . The System Properties window appears. Select the
🌐
Eleven Forum
elevenforum.com › windows support forums › tutorials
Create New Environment Variables in Windows 11 | Windows 11 Forum
November 20, 2024 - Substitute [variable name] in the command above with the actual variable name (ex: "Downloads") you want used as the environment variable (ex: "%Downloads%" or "$Env:Downloads"). Substitute [variable value] in the command above with the actual variable value (ex: "C:\Users\Brink\Downloads") you want referenced by the environment variable. For example: [Environment]::SetEnvironmentVariable("Downloads","C:\Users\Brink\Downloads","User") 3 You can now close Windows Terminal if you like.
🌐
Windows 10 Forums
tenforums.com › tutorials › 121664-set-new-user-system-environment-variables-windows.html
Set New User and System Environment Variables in Windows - Windows 10 Help Forums
The variable (ex: "%UserProfile%") is used as a type of shortcut of the value (ex: "C:\Users\<username>"). There are two types of environment variables: user environment variables (set only for current user) and system environment variables (set for all users). This tutorial will show you how to set (create) new user and system environment variables in Windows 7, Windows 8, and Windows 10.
Top answer
1 of 4
124

This batch file must be run as administrator to update system environment variable Path and set/update system environment variable JAVA_HOME.

@ECHO OFF

:: %ALLUSERSPROFILE% = C:\ProgramData
:: %ProgramFiles% = C:\Program Files
:: %USERPROFILE% = C:\Users\Ruben
:: %SystemDrive% = C:
:: %SystemRoot% = C:\WINDOWS
:: No spaces in paths
:: CMD inherits the environment variables when it is start from Windows shell.
:: CMD must be restarted to inherit the updated system environment variables.
:: Use console 2 https://sourceforge.net/projects/console/

REM Assign all Path variables
SET "PHP=%SystemDrive%\wamp\bin\php\php5.4.16"
SET "SYSTEM32=%SystemRoot%\System32"
SET "ANT=%USERPROFILE%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin"
SET "GRADLE=%SystemDrive%\tools\gradle-1.6\bin"
SET "ADT=%SystemDrive%\tools\adt-bundle-windows-x86-20130219\eclipse\jre\bin"
SET "ADTTOOLS=%SystemDrive%\tools\adt-bundle-windows-x86-20130219\sdk\tools"
SET "ADTP=%SystemDrive%\tools\adt-bundle-windows-x86-20130219\sdk\platform-tools"
SET "YII=%SystemDrive%\wamp\www\yii\framework"
SET "NODEJS=%ProgramFiles%\nodejs"
SET "CURL=%SystemDrive%\tools\curl_734_0_ssl"
SET "COMPOSER=%ALLUSERSPROFILE%\ComposerSetup\bin"
SET "GIT=%ProgramFiles%\Git\cmd"
SET "JAVA_HOME=%ProgramFiles%\Java\jdk1.7.0_21"

REM Set JAVA_HOME variable as system environment variable.
setlocal EnableExtensions DisableDelayedExpansion
set "JaveHomeReg="
for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v JAVA_HOME 2^>nul') do (
    if /I "%%G" == "JAVA_HOME" (
        set "JaveHomeReg=%%I"
        if defined JaveHomeReg goto SetJavaHome
    )
)
:SetJavaHome
setlocal EnableDelayedExpansion
if /I "!JaveHomeReg!" == "!JAVA_HOME!" endlocal & goto SetSystemPath
endlocal
if exist %SystemRoot%\System32\setx.exe (
    %SystemRoot%\System32\setx.exe JAVA_HOME "%JAVA_HOME%" /M >nul
) else (
    %SystemRoot%\System32\reg.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v JAVA_HOME /t REG_SZ /d "%JAVA_HOME%" >nul
)

REM Update the system Path variable.
:SetSystemPath
set "SystemPath="
for /F "skip=2 tokens=1,2*" %%G in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do (
    if /I "%%G" == "Path" (
        set "SystemPath=%%I"
        if defined SystemPath goto ProcessPath
    )
)
:ProcessPath
setlocal EnableDelayedExpansion
rem Is the system environment variable PATH not present or has an empty value?
if not defined SystemPath set "PathToSet=%%SystemRoot%%\System32;!PHP!;!NODEJS!;!COMPOSER!;!YII!;!GIT!" & goto UpdatePath
endlocal

rem It is not possible to add folder paths to the system environment
rem variable PATH if this variable as stored in the registry contains
rem already a folder path with an equal sign or enclosed in double quotes.
set "PathCheck=%SystemPath:"=%"
for /F "eol=| tokens=1 delims==" %%I in ("%PathCheck%") do if not "%%I" == "%PathCheck%" set "ErrorChar==" & goto ErrorPath
setlocal EnableDelayedExpansion
if "!PathCheck!" == "!SystemPath!" goto CheckPath
endlocal
set "ErrorChar=""
goto ErrorPath

rem Determine if the system environment variable PATH ends already
rem with a semicolon in which case no additional semicolon must
rem be added left to the folder paths to add.
:CheckPath
if "!SystemPath:~-1!" == ";" (set "Separator=") else set "Separator=;"
set "PathCheck=!SystemPath!%Separator%"
set "PathToSet=!PathCheck!"

rem For each folder path to add check if the folder path without or with a
rem backslash at the end with a semicolon appended for an entire folder path
rem check is already in the system PATH value. This code does not work on
rem path to add contains an equal sign which is fortunately very rare.
if not "!PathCheck:%PHP%;=!" == "!PathCheck!" goto CheckNodeJS
if not "!PathCheck:%PHP%\;=!" == "!PathCheck!" goto CheckNodeJS
set "PathToSet=!PathToSet!!PHP!;"

:CheckNodeJS
if not "!PathCheck:%NODEJS%;=!" == "!PathCheck!" goto CheckComposer
if not "!PathCheck:%NODEJS%\;=!" == "!PathCheck!" goto CheckComposer
set "PathToSet=!PathToSet!!NODEJS!;"

:CheckComposer
if not "!PathCheck:%COMPOSER%;=!" == "!PathCheck!" goto CheckYII
if not "!PathCheck:%COMPOSER%\;=!" == "!PathCheck!" goto CheckYII
set "PathToSet=!PathToSet!!COMPOSER!;"

:CheckYII
if not "!PathCheck:%YII%;=!" == "!PathCheck!" goto CheckGit
if not "!PathCheck:%YII%\;=!" == "!PathCheck!" goto CheckGit
set "PathToSet=!PathToSet!!YII!;"

:CheckGit
if not "!PathCheck:%GIT%;=!" == "!PathCheck!" goto CheckUpdate
if not "!PathCheck:%GIT%\;=!" == "!PathCheck!" goto CheckUpdate
set "PathToSet=!PathToSet!!GIT!;"

:CheckUpdate
rem Do nothing if no folder path to add to system environment variable PATH.
rem Remove otherwise the semicolon from the end of the PATH string to set.
if "!PathToSet!" == "!PathCheck!" goto EndBatch
set "PathToSet=!PathToSet:~0,-1!"

:UpdatePath
set "UseSetx=1"
if not "!PathToSet:~1024,1!" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
    %SystemRoot%\System32\setx.exe Path "!PathToSet!" /M >nul
) else (
    set "ValueType=REG_EXPAND_SZ"
    if "!PathToSet:%%=!" == "!PathToSet!" set "ValueType=REG_SZ"
    %SystemRoot%\System32\reg.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v Path /t !ValueType! /d "!PathToSet!" >nul
)
goto EndBatch

:ErrorPath
echo(
echo ERROR: Folder paths to add to system environment variable PATH are:
echo(
setlocal EnableDelayedExpansion
echo !PHP!
echo !NODEJS!
echo !COMPOSER!
echo !YII!
echo !GIT!
echo(
echo The system environment variable PATH contains the character '%ErrorChar%'.
echo This procedure for updating the system environment variable PATH
echo does not support updating the variable PATH with that character.
echo(
echo The folder paths must be manually added to the system environment variable PATH.
echo Please click on Windows Start button, type on keyboard the word environment,
echo and click on suggested item "Edit the system environment variables".
echo Add or edit the environment variable PATH in the lower list of system
echo environment variables and append the folder paths as displayed here
echo which are not already in the list of folder paths.
echo(

:EndBatch
endlocal
endlocal

PAUSE

The code for the update of the system environment variable Path is derived from:
What is the best practice for adding a directory to the PATH environment variable on Windows?

2 of 4
10

I come at this question with a Linux perspective. Usually setting an environment variable in Linux ($myVar=1) only sets it for the current process but not any child process that it spawns.

To allow any child process to read a variable you need to export envVar=2. In Windows the set command already does this for you. This is generally what you want.

The setx command sets a variable permanently for the current user, but strangely enough this is not reflected in the current process, you will need to open another cmd.exe window for it to take effect.

C:\> set foobar=1

C:\> powershell "echo ${env:foobar}"
1

C:\> setx barfoo 2

SUCCESS: Specified value was saved.

C:\> powershell "echo ${env:barfoo}"  # not present

C:\> 

Also notice the strictly necessary syntax difference between set and setx.

🌐
NinjaOne
ninjaone.com › home › blog › it ops › how to view and manage environment variables in windows
How to View and Manage Environment Variables In Windows | NinjaOne
March 12, 2026 - Type [System.Environment]::SetEnvironmentVariable(“MY_VAR”, “TestValue”, “Machine”) and press Enter. Remember: Use “User” for variables that apply only to your account or “Machine” for variables that apply to the entire system.
🌐
AOMEI Software
aomeitech.com › aomei software › windows backup tips › how to set environment variables in windows 11/10
How to Set Environment Variables in Windows 11/10
December 10, 2024 - If you want to set environment variables for an installed application, let's look at an example of how to set environment variables. You have installed Audacity and want to add its path to the environment variable (EV) 1. Click "New" under User Variables to create an EV. 2. In the New User Variable window that pops up, enter the Variable name.
🌐
NTU Singapore
www3.ntu.edu.sg › home › ehchua › programming › howto › Environment_Variables.html
Environment Variables for Java Applications - PATH, CLASSPATH, JAVA_HOME
Environment Variables in Windows are NOT case-sensitive (because the legacy DOS is NOT case-sensitive). They are typically named in uppercase, with words joined with underscore (_), e.g., JAVA_HOME. To list ALL the environment variables and their values, start a CMD and issue the command "set", as follows,
🌐
Sigasi
sigasi.com › knowledge › how_tos › setting-environment-variables
Setting Environment Variables - Sigasi
September 23, 2024 - Click on Advanced system settings on the left side. In the System Properties window, click on Environment Variables.