To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
set NEWVAR=SOMETHING
you are just setting it in the current process space.
According to this page you can use the setx command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
set NEWVAR=SOMETHING
you are just setting it in the current process space.
According to this page you can use the setx command:
setx NEWVAR SOMETHING
setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit
We can also use "setx var variable /M" to set the var to system environment variable level instead of user level.
Note: This command should be run as administrator.
Is there a way to set environment variables that only apply to the command prompt (but to all future sessions)?
command line - Set Environment Variables Windows - Stack Overflow
Setting a system environment variable from a Windows batch file? - Stack Overflow
command line - Adding a directory to the PATH environment variable in Windows - Stack Overflow
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.
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.
Videos
On Windows 10 x64, is there a way for me to do the following?
-
Specify some environment variables
-
Have those environment variables be set when I start the Windows command prompt
-
Have my environment variables revert to normal when I end the Windows command prompt
-
(optional) Have those environment variables not apply to other stuff that I run outside of the command prompt, even while the command prompt is running
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.

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(!).
The XP Support Tools (which can be installed from your XP CD) come with a program called setx.exe:
C:\Program Files\Support Tools>setx /?
SETX: This program is used to set values in the environment
of the machine or currently logged on user using one of three modes.
1) Command Line Mode: setx variable value [-m]
Optional Switches:
-m Set value in the Machine environment. Default is User.
...
For more information and example use: SETX -i
I think Windows 7 actually comes with setx as part of a standard install.
Simple example for how to set JAVA_HOME with setx.exe in command line:
setx JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
This will set environment variable "JAVA_HOME" for current user. If you want to set a variable for all users, you have to use option "/m" (or -m, prior to Windows 7).
Here is an example:
setx /m JAVA_HOME "C:\Program Files (x86)\Java\jdk1.7.0_04"
Note: you have to execute this command as Administrator.
Note: Make sure to run the command setx from an command-line Admin window
Option 1
After you change PATH with the GUI, close and reopen the console window. This works because only programs started after the change will "see" the new PATH. This is because when you change the PATH environment variable using the GUI tool, it updates the variable for future processes but not for anything currently running.
Option 2
This option only affects your current shell session, not the whole system. Execute this command in the command window you have open:
set PATH=%PATH%;C:\your\path\here\
This command appends C:\your\path\here\ to the current PATH. If your path includes spaces, you do not need to include quotation marks.
Breaking it down:
set– A command that changes cmd's environment variables only for the current cmd session; other programs and the system are unaffected.PATH=– This signifies thatPATHis the environment variable to be temporarily changed.%PATH%;C:\your\path\here\– The%PATH%part expands to the current value ofPATH, and;C:\your\path\here\is then concatenated to it. This becomes the newPATH.
WARNING: This solution may be destructive to your PATH, and the stability of your system. As a side effect, it will merge your user and system PATH, and truncate PATH to 1024 characters. The effect of this command is irreversible. Make a backup of PATH first. See the comments for more information.
Don't blindly copy-and-paste this. Use with caution.
You can permanently add a path to PATH with the setx command:
setx /M path "%path%;C:\your\path\here\"
Remove the /M flag if you want to set the user PATH instead of the system PATH.
Notes:
- The
setxcommand is only available in Windows 7 and later. You should run this command from an elevated command prompt.
If you only want to change it for the current session, use set.
Here’s how I’ve done it many times via command line. Run setx /? at a cmd prompt for all the options. /M makes it a system wide variable.
Ex.
ORACLE_HOME is the variable name.
The C:\ path is the value of the variable.
SETX ORACLE_HOME C:\Oracle\product\11.2.0\instantclient_11_2 /M
Is there a command line I can use to set PC and Server environment variables? I have several I have to type in often. It would be nice to write a script to enter them for me.