Hello everybody!
In this video I’m going to tell you about environment variables in Windows and why we
need them.
How to add a program to variables to enable quick start from the command prompt, how to
use short paths to system folders, and how to find and and view environment variables
in the registry
and in the command prompt.
Environment variable is a very useful function mostly demanded by system administrators.
Most often, they are required to write universal scripts running on computers with various
settings which may change.
Also, in Windows there is an environment variable “Path” which allows quicker access to
programs from the command prompt and without using the path to the folder containing such
a program.
Adding a folder to the “path” variable
If you often work with the command prompt, you may have asked yourself a question: why
some commands can be entered without a full path, while starting others requires their
full path to be given, or even asks you to go to the folder containing such program.
The matter is that the operating system has a certain variable, PATH, which stores paths
to popular system folders; they are checked to see if the executable file you are using
in the command prompt is there.
Now, how can we add such a folder, so that when we use the command prompt later, we will
not have to go to the directory containing the program, or enter the path to its folder?
To add it, open System Properties: to do it, enter “sysdm.cpl” into the search field
or just right-click on “This PC”, select “Properties,” go on to “Advanced System
Settings,” and find “Environment Variables” in the tab “Advanced.”
In the window that opens, find “Path”, open it for the current user in “User Variables”,
and for general access, in “System Variables.”
Select it, click “Edit,” then “New” and paste the path to the necessary folder,
or click “Browse” and show the path, then click OK.
For example, I will add the path to the folder containing Google Chrome browser (C:\Program
Files (x86)\Google\Chrome\Application\); after that, when I open the command prompt, type
Chrome and press Enter, the browser will start.
After you have added a folder, restart the command prompt, otherwise the command will
not work properly.
This way, any folder containing a program you need can be added to environment variables.
Viewing environment variables in windows registry
You can also view environment variables in the registry.
To open the registry, enter “regedit” in the search field and run it, then follow
the path HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment This is where you can see environment variables.
You can add a variable into the registry in two ways.
You can right-click in the registry editor and select “New”, or use the command prompt,
for example, for the variable named “var” and contents “val”; I will do it by entering
the following command REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment" /v var /t REG_EXPAND_SZ /d val
After that, a variable with the value “var” will appear in the registry.
You can also view variables in the command prompt by running the command SET to show
the list of all variables, and to save all environment variables and their values into
a text file, run this command set > c:\env_var.txt
and a file containing the list of all variables will appear in the specified location.
How to create a shortcut using a short path, and how to work with variables
All popular system folders are listed in environment variables, so you can use them to create a
shortcut without specifying the full path.
For example, I’m going to create a registry shortcut using a short path to such folder.
Right-click, New, shortcut, and in the path, I’ll write %windir%\regedit.exe, and the
registry shortcut is created.
I have not given the full path which looks like this: C:\windows\regedit.exe, but used
a short link instead.
You can also use such short commands to quickly open system folders, for example, user’s
folders; to do it, I’ll type %homepath% into the search field and press Enter; the
current user’s folder will open in a new window.
In the same way, you can get into other folders, for example, Appdata or Temp: in the search
field, enter %appdata% or %Temp%, and the necessary folder will open.
To get the value of an environment variable from the command prompt, the command “echo”
is used.
For example, I will enter this command echo %PROCESSOR_ARCHITECTURE%
which shows the processor type for the current computer.
To modify the value of a variable, use the command SET; for exampe, to change the value
of Temp, enter the following SET TEMP=C:\TEMP
The command SET is used for one-time actions, but for regular action you should modiy the
value in the environment variable settings.
You can find the link to the list of variables in the description under the video.
That is all for now.
Hit the Like button and subscribe to our channel.
Leave comments to ask questions.
Thank you for watching.
Good luck.