Computer lessons

Setting the PATH system variable. SET command - working with Windows environment variables Windows 7 environment variables path

When the operating system starts a program, it starts a new process and somehow passes it information about the settings of the environment, or environment (in English the term environment is used). This information consists of a set of variables containing some values. A process can obtain these values ​​by accessing the desired variable by name. For example, to find out where the directory is that the operating system recommends to use for storing temporary files, you need to get the value of the TEMP environment variable.

How can I view the values ​​of environment variables?

In the Windows console you can view the value of this variable by running the command echo %TEMP% , in the PowerShell console you need to run the command echo $Env:TEMP , and in the Linux or MacOS console you need to run the command echo $TEMP .

If you are writing a program in the Python programming language, the value of this variable can be obtained like this:

import os temp = os . environ["TEMP"]

In Java this can be done like this:

String temp = System . getenv(). get("TEMP");

In C#, a similar action looks like this:

string temp = System . Environment. GetEnvironmentVariable("TEMP");

What does the PATH environment variable affect?

Using environment variables, you can transfer information not only to running processes, but also to the operating system itself. It also reads and uses the values ​​of environment variables, so you can control some aspects of the operating system's behavior by changing environment variables.

The PATH variable contains a list of directories in which the operating system tries to search for executable files if the user did not explicitly specify the path to the desired executable file at startup.

Let's imagine that a Windows computer has two different versions of the Python programming language interpreter installed. This can be done by installing them in different directories, for example, C:\Python27 and C:\Python34. The executable file for both versions is called python.exe.

In order to run the executable file of the desired version, you can specify the full path to it, for example, C:\Python34\python.exe:

But I’m too lazy to indicate the full path every time, and I also have to remember it.

An alternative is to add the path to the directory where this executable file is located to the PATH environment variable, and then you can run it by specifying only the name. And to find out where it is (according to the operating system) it is located, you can use the where command in the Windows operating system or the which command in the Linux or MacOS operating system.

This variable contains a list of directories in which the operating system should look for executable files. The separator is a semicolon (;) on Windows and a colon (:) on Linux and MacOS.

Please note that in the PATH variable you need to add not the paths to the executable files, but the paths to the directories where they are located!

PATH Variable and Utility Programs

It is not necessary to add the paths to all directories in which executable files are located on your computer to the PATH variable. Most likely, you launch most programs “through the start menu.” The PATH variable has no effect on this launch method. It is important to configure it so that you can quickly and conveniently launch all sorts of small programs from the console.

For example, this variable usually includes the path to the “standard” places where various small utility programs are located. In the Windows operating system this is the directory C:\Windows\system32, in the Linux and MacOS operating systems the directory is /usr/bin.

It is thanks to this that we can, for example, use the find utility in the Windows console to search for files or the telnet utility to establish a remote connection using the protocol of the same name, simply by specifying their name, and not the full path c:\Windows\system32\telnet.exe .

When you have a new utility program, the question arises - where to put it? On the one hand, it can be placed in C:\Windows\system32 or /usr/bin . But if you don't like to litter standard directories, then make some special directory, put all such small programs in it, and add the path to this directory to the PATH environment variable.

PATH is an environment variable and is a list of folders that is used by the operating system to search for executable files (*.EXE). In practice, if the folder is added to PATH, executable files can be run from the command line without specifying the full path to them.

  • To see a list of folders included in the PATH variable, simply type PATH on the command line.
  • You can add a folder to PATH using the Windows GUI. To do this, open the system properties dialog box (WIN+PAUSE), on the tab Additionally press the button Environment Variables, in the system variables section, select PATH and press the button Change.

As part of Windows auto-installation, we are, of course, interested in the issue of adding a folder to PATH from the command line during system installation.

PATH command

This command adds the specified folders to PATH, but the changes are valid only during the current command session(i.e. if you run this command from a batch file, the added folders will only be in PATH for as long as it runs).

Path=%PATH%;"%systemdrive%\system32\mytools";"%programfiles%\Opera"

pathman utility

pathman /as "%systemdrive%\system32\mytools";"%programfiles%\Opera"

Advice. You can collect all your favorite command line utilities into one folder and add it to your PATH. In the example above, my utilities are collected in %systemdrive%\system32\mytools.

AutoIt script

;what path should be added to the Path variable$addtopath=@ProgramFilesDir&"\7-Zip" ;retrieve the current contents of the Path variable$curpath=RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","Path")

Variable PATH is a system variable with which the operating system finds the necessary executable objects on the command line or terminal window. The variable parameter contains a list (separated by semicolons) ; ) directories in which the executable file will be searched when calling the command from the console.

In the operating system Windows system variable PATH can be set using the system utility in Windows Control Panels.

Let's describe how to change the value of a variable PATH in the operating system Windows 10.

On the menu Start execute the command System(Control Panel → System and Security → System):

Click on the link Advanced System Settings:

Open the Environment Variables window:


In chapter Environment Variables And System Variables select the environment variable PATH. Click Change. If the variable PATH does not exist, click Create.

To change system environment variables, you must have the appropriate rights. If there are none, you should create a user variable.


In the window " Change environment variable" (or New system variable) specify the value of the environment variable PATH, then confirm the action by pressing the button OK.


If you use a variable PATH not for the command line, but for other applications, for example PHP module, you should restart your computer.

Instructions

Right-click on the My Computer icon located on your desktop or Start menu. In the context menu that appears, select the bottom line “Properties” - a new “System Properties” window will open. You can also open the System Properties window by pressing the Windows + Pause Break hotkey combination. If you are using the Windows 7 operating system, then also right-click on the “My Computer” icon, select “Properties”, and then select “Advanced system settings” on the left side of the properties window.

In the “System Properties” window, go to the “Advanced” tab by left-clicking on it - you will see three sections of additional system settings. Below them there will be two more buttons - “Environment Variables” and “Error Report”. You need environment variables - click on the appropriate button.

The Environment Variables window contains two categories of variables, one being User Environment Variables and the other being . Find the path variable in the list of system variables and select it by clicking the left mouse button.

Now, with the path variable selected, click on the “Change” button located under the list window - a small “Change system variable” window will open, where two input lines will be located - “Variable name” and “Variable value”. Change the value of the path variable to whatever you want.

Another way to change the value of the path variable is as follows: in the “Environment Variables” window, click on the “Create” button, then in the window that opens, in the “Variable Name” field, enter “path” and in the “Variable Value” field, enter the desired value. This will change the current value of the path variable to the one you just entered.

Video on the topic

An environment variable called Path is used by operating system components and applications installed on it to obtain directory addresses in which to search for executable files. Some addresses are present in this variable by default and the user cannot change them, but he can add (“write”) additional addresses to it.

Instructions

Right-click the “My Computer” icon on the desktop and select “Properties” from the pop-up context menu. The same can be done with the “Computer” item in the main menu of the operating system on the “Start” button. Or you can simply press the win + pause hotkey combination - any of these actions will launch the OS component called “System Properties”.

Go to the “Advanced” tab of the window that opens and click the “Environment Variables” button located at the bottom. Another window will open with two tables placed in it - the operating system installation you need is placed at the top (“User Environment Variables”). Select the line that has the word Path in the “Variable” column, and then click the “Edit” button under this table. As a result, a third and final dialog box will open with the title “Changing a user variable” and two fields to fill out.

Enter the desired path in the “Variable value” field. If it already contains any entry, then add a new one to the right, separating it from the existing one with a semicolon (;). In order not to make a mistake in writing the full address to the desired directory, it is better to copy the path to it in Windows Explorer - open it (win + e), go to the desired folder, select the full path in the address bar of the file manager (ctrl + a), copy (ctrl + c), return to the dialog box and paste the contents of the clipboard (ctrl + v) into the Variable Value field.

Leave the value in the “Variable Name” field unchanged (Path should remain there) and click OK. After this, successively press the same OK buttons in the other two open windows. This completes the procedure for adding a new value to the Path variable.

Video on the topic

All Nokia mobile phones are made on the S40 and S60 platforms. This means that java machines are automatically integrated on them. Therefore, to install a J2ME application on such a phone, you just need to copy it to the phone's built-in memory or to a memory card.

Instructions

Launch the Internet browser of your Nokia mobile phone to install Java. You need to download the JAR file. For other phones, you would also need to download the JAD file. However, due to the greater demand for this particular file type, it will be easier for you to download it.

Please note that automatically, along with the JAD file, a JAR file will also be downloaded to your phone. Use the phone's built-in browser if it is based on the S40 platform. This is necessary so that after downloading the file will be automatically installed. Those. installing Java is no longer necessary. Go to the "Games" or "Applications" section. In the list of programs you will find the newly installed file.

Do the following to install the Java application if yours has a memory card. Turn off your phone. Remove the memory card from it. Take a card reader. Use it to connect your phone memory card to your computer. Copy all the Java applications you are interested in to the appropriate folder. After this, remove the memory card correctly and insert it into the phone.

Do the following if your phone is based on the S60 platform. Launch your mobile phone's built-in browser. Download the required JAR or JAD file. You can also use a third-party browser, such as Opera Mobile, Opera Mini or some other. The thing is that the built-in browser will automatically save the file to the UCDownloaded folder, and with a third-party browser you can set any folder as the save location on the memory card of your mobile phone.

For correct installation, remove the memory card from your mobile phone. Using a card reader, connect it to your personal computer. Then install the JAR file into the applications folder on the memory card. The installation does not take long and should not cause any complications. After it is completed, remove the memory card and insert it into the phone.

The operation of setting an environment variable (environment) can be performed by the user using standard tools of the Microsoft Windows operating system and does not require the use of additional third-party software.

Try entering in the Run window (Win + R) wmplayer and press Enter - Windows Media Player will open. Now do the same on the command line. The player will not start because the path to it was not found! Why is this happening?

Blog reader Andrey asked by email in what cases it is not necessary to enter the full path to them to launch executable files. The question seemed elementary to me, and I briefly invited the reader to pay attention to the PATH variable.

PATH variable

Environment variable PATH contains paths in which Windows automatically searches for executable files (EXE, CMD, VBS, etc.) when executing a command. Initially, only the main system locations are included in the variable, so programs from the Windows and System32 folders can be launched without specifying the full path.

How to view the contents of the PATH variable

During installation, some programs write the path to their folder there, which you will probably verify by running the command in the console path, showing system and user variables together.

When the executable file is located in one of the locations known to Windows, you do not have to enter the full path to the file. I use this property of the operating system to quickly launch my favorite Nirsoft utilities and other programs from my chest (the picture shows that the Tools folder has been added to PATH).

How to add your own paths to the PATH variable

You can add your own paths by changing the system PATH variable, or by creating a user variable with the same name. I explained the difference between the types of variables in one of the quizzes. It also tells you how to change environment variables in GUI. Note that paths are separated by semicolons.

You can quickly add your paths to PATH from the command line using the utility setx, included with Windows 7. The following is an example of adding the path C:\myfolder to systemic PATH variable (the command line must be run as administrator).

For /f "tokens=2*" %a In ("Reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path") Do Set "systempath=%b" set newpath=%systempath%; C:\myfolder1 setx /m path "%newpath%"

First using the command reg the list of paths is read from the PATH system variable stored in the registry. Then the command set sets a variable newpath with the desired path within the current command line session, and the command setx/m makes the new path permanent for systemic variable (parameter /m).

A custom variable can be set without administrator rights using a similar approach. Adding a new path to an existing one custom PATH variable is implemented like this:

For /f "tokens=2*" %a In ("Reg query "HKCU\Environment" /v Path") Do Set "userpath=%b" set newpath=%userpath%;C:\myfolder2 setx path "%newpath %"

Please note that the code above is designed to be executed on the command line. In a command file (CMD), the percent symbols on the first line must be double.

Strictly speaking, it was possible to do without setx, because the reg can not only read data from the registry, but also write it there. But in many cases with setx Easier to work with more compact syntax.

Of course, I didn’t describe all this in such detail for Andrey, but simply gave him direction. However, the next day he wrote to me that he knew all this (I am a mediocre telepath:) and asked the question with which I began today’s story. This was already more interesting, and I promised to cover the topic in the blog!

App Paths registry key

Indeed, without specifying the full path, you can run some standard Windows programs from the Run window, but not from the command line. In addition to Windows Media Player, this is, for example, Paint ( mspaint) and Wordpad ( wordpad). The same is true for MS Office applications - check the command excel or winword!

The difference between the Run window and the Command Prompt is that the Windows shell (explorer) has more capabilities than the console command interpreter. In this case, it's all about the function ShellExecuteEx, with which the shell is equipped. When you run an executable without specifying its full path, the function searches:

  • current folder
  • Windows and System32 folders
  • registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

How the App Paths section works

Let's look at how App Paths works using Windows Media Player as an example.

  • a subsection has been created with an alias for the executable file (in this case it is wmplayer.exe)
  • in the parameter Default the full path to the file is specified. If a variable is used in the file path, the parameter must be an extensible string (REG_EXPAND_SZ). When specifying an absolute path, you can use a regular string parameter (REG_SZ).
  • in the parameter Path the program's working folder is specified

It works very simply. You enter a file alias in the Run window or the address bar of Explorer, and the system automatically looks in the specified path.

How to speed up your work with App Paths

You can use this registry key to quickly launch programs whose shortcuts you do not need in the taskbar or on the desktop. For example, to search and replace text files, I use the BKReplacem program (replacem.exe), which has its own folder inside the PortableSoft folder. In the App Paths section I created a subsection bkr.exe and indicated the full path to the utility. Now its launch comes down to executing bkr in the Run window.

By the way, do not forget to enclose paths containing spaces in quotes. And, I hope, you have already guessed that you can shorten the command to one letter. Continuing with this example, I could create a subkey b.exe. In general, a program can have any number of aliases, as you will see below.

Another use I've found for App Paths is to run cmd.exe with full rights. I've been doing without the UAC prompt for a long time now, thanks to running the command line from the Task Scheduler. Having created a cmda.exe subkey, I specified in it the path to the batch file that performs the task.

There is only one line in it:

Schtasks /run /tn CMD_Admin

Now just enter the command in the “Run” window cmda to open Command Prompt as administrator.

What interesting things can be found in the App Paths section

First, I'm sure you'll find many of the programs you have installed there. Instead of specifying the path to their folder in the PATH variable, programs register their executable file in the App Paths section, following Microsoft recommendations.

Secondly, there are subsections WORDPAD.EXE And WRITE.EXE, both leading to the wordpad.exe file.

The Write program, which was part of the first Microsoft operating systems, was replaced in Windows 95 by WordPad. You will also find a subsection pbrush.exe, which refers to mspaint located in System32.

The Write and Paintbrush programs have not been in Windows for about 15 years, but mention of them is still contained in the system! And this brings us to the conversation about when and why the App Paths section was introduced in Windows.

History of App Paths

The App Paths section appeared in Windows 95 as an antidote to the clogging of the PATH path, which was specified in the file autoexec.bat. Programs traditionally added the paths to their folders there, as is still sometimes done with the environment variable of the same name. When the system booted, the file was read and the programs ended up in the system path.

By the way, the old autoexec.bat method still works, allowing you to run executable files without specifying the path, although there is no point in using it anymore.

The main problem for developers was that finding the correct SET PATH line in autoexec.bat was a non-trivial task. In this case, you could not insert your line at the beginning of the file, since another command below could override the variable.

In addition, adding a path to PATH in order to point Windows to one single program was not rational, akin to shooting sparrows with a cannon. That's when the Windows 95 developers came up with a solution with a registry section that allowed you to specify paths to specific executable files.

Why does this section still have subsections for Write and Paintbrush? This is how Windows ensures program compatibility!

Theoretically, some ancient program could rely on its peers, whose heirs have already changed their name or location. To prevent older applications from breaking, the App Paths registry key is used.

Pivot table

So, let's sum it up! The easiest way is to compare the capabilities of the Windows shell and the system command interpreter in tabular form.

In this form, it becomes clear not only a wider range of searches for executable files in Explorer, but also the not entirely obvious dependence of the command line on the PATH variable. It is its paths that influence whether it is necessary to specify the path to files located in system folders in the console.

Finally, the App Paths section adds value by allowing you to specify short aliases for executables, making them easier to run.

Are you using the App Paths registry key or your own environment variables? If yes, then Tell us in the comments how they make your work easier!