What are environment variables
They are special feature of OS and/or application which allow easy and standardized way of working. You can open them by
- click on Start Menu
- right click on Computer
- go to Advanced System Settings
- tab Advanced
- Environmental Variables
There you have system level variables (path, windir..) and user level(tmp, temp, home).
P.S. Be very careful if you are changing environmental variables because it can lead to unstable or even not working system!
Read environment variables by command line
Command SET is used to see all variables. Just type:
The output is like:
The same command can be used for variables with names starting with prefix or exact name.Let say that you want to check and read only JAVA_HOME from the environment variables(echo command will do similar job) :
and you will get the following :
You can write the output to file output.txt by:
SET > output.txt
Set environment variables command line
In order to set a variable for one session only you can use:
Check result by
This will set it up in the current process space only.
To make the environment variable persistent and accessible globally you need to set it in the registry.
setx NEWVAR SOMETHING
setx is built into Windows 7 and later