kancboom.ru

In some cases, when starting a program, you do not need to specify the full path to it. Windows environment variables Path variable in windows 7

Those who have ever used command line utilities know that it is much more convenient to type a command right away, without using the path to this utility, and without even going to the desired directory, so today we’ll talk about system variable path in Windows, we’ll find out what it’s for and how it can be changed.

Today we will not talk about what the command line is and what standard command line utilities are in Windows, since we have already talked about this in the material Windows Command Line Basics.

What is the path system variable for?

System variable path We need it so that we can add our utilities to the CMD.exe command line, and more specifically, add directories, i.e. paths to these directories so that the OS could determine by the name of the utility where it is located and run it.

Speaking as an example, let's say you open the command line, type the command ipconfig ( serves to configure network interfaces) and at the time of launch, the command line does not know where this utility is located, so it starts looking for it. First in the current directory, then in the system directories, which are precisely indicated in the system path variable. In other words, if you wrote your own console program and want to run it in the same way as ipconfig, then you will not be able to do this, since the OS does not know where the program itself is located. Therefore, we need to go to the directory with the program or write the full path to the executable file in order to launch our utility. Therefore, if you often use some console program that is not in the standard Windows build and do not want to copy it to the system directories, then it would be best to create your own directory and add it to the system path variable.

Example

Let's say we wrote a console program; for example, we will have a simple bat file with the following simple command:

Echo Hello! Pause

Note! If you want the Cyrillic alphabet to be displayed on the command line, then save the bat file with OEM 866 encoding; this can be done using the Notepad++ text editor.

Save with name privet.bat on drive C in the test directory.

Now we launch the command line (Windows 7 OS) “Start -> Run -> cmd”.

And let’s immediately try to run our utility and see what comes out of it:

As you can see, the command line does not know what kind of program it is. We can, of course, write it differently, for example:

Those. indicating the full path to the utility, then it will certainly start. Or you can also go to the test directory and run the utility from there, for example:

In this case, the program will also start. But you must admit that these are all unnecessary movements, especially if we are going to use this program quite often. So let's change the path system variable.

Note! If you don’t like the background or font color of the command line, then you can easily change it, as we discussed in the article Customizing the appearance of the Windows command line.

Changing the system path variable in Windows 7

To do this we open “Control Panel -> System -> Advanced system settings.”

Then select " Environment Variables».

Afterwards you will see a window “ Environment Variables " and you are at the bottom of the window in the list " System variables » look for the variable path and press "Change".

As a result, a small window will open “ Changing a system variable", where are you in the field " Variable value» add at the end, separated by a semicolon, the path to the directory in which you will store your console utilities. For example, I specified C:\test. After entering, click “OK”.

Now let's check it out. We will do exactly as we did the first time, i.e. open the command line and immediately write privet.bat and look

As you can see, this time everything worked for us, even without specifying the full path.

I will say again that this will be useful for those who often use console utilities; by the way, many application packages that you install yourself add the desired path to path, doing it for you.

I think that's enough, if you have questions, ask in the comments. Good luck!

This section concerns:
  • Platforms: Solaris SPARC, Red Hat Linux, SUSE Linux, Oracle Linux, Windows 10, Windows 8, Windows 7, Vista, Windows XP, Mac OS X

The instructions on this page are intended only for experienced users and system administrators.


General information

  • Variable PATH is a system variable that the operating system uses to find the desired executable objects on the command line or terminal window.
  • System variable PATH can be set using system utility in the Windows Control Panel or using the Linux and Solaris shell startup file.
  • On computers running Windows or Mac OS X making changes to the PATH system variable usually not required.

Windows

Windows 10 and Windows 8
  1. In the "Search" line, search for: System (Control Panel)
  2. Click on the link .
  3. Click Environment Variables. In chapter Environment Variables Change
  4. In the window (or New system variable OK OK.
Windows 7
  1. On the desktop, right-click on the icon Computer.
  2. From the context menu, select Properties.
  3. Click on the link Advanced System Settings.
  4. Click Environment Variables. In chapter Environment Variables select the PATH environment variable. Click Change. If the PATH variable does not exist, click Create.
  5. In the window Changing a system variable(or New system variable) specify the value of the PATH environment variable. Click OK. Close other open windows by clicking OK.
  6. Reopen the command prompt window and run the java code.
Windows XP
  1. Click Start, select Control Panel, double click on System and select a tab Additionally.
  2. Click Environment Variables. In chapter Environment Variables select the PATH environment variable. Click Change. If the PATH variable does not exist, click Create.
  3. In the window Changing a system variable(or New system variable) specify the value of the PATH environment variable. Click OK. Close other open windows by clicking OK.
  4. Reopen the command prompt window and run the java code.

Mac OS X

To run another version of Java, provide the full path or use the java_home tool:

% /usr/libexec/java_home -v 1.8.0_73 --exec javac -version

Solaris and Linux

  1. To see if the path is configured correctly:
    In terminal windows, enter:
    % java -version
    The version of the java tool will be displayed if it cannot be found. If the version is outdated or an error appears java: command not found, then the path is set incorrectly.
  2. Determine which executable version of java is the first one found in a variable PATH
    In a terminal window, enter:
    % which java
Final path setup

To set the path permanently, configure it in the startup file.
Note. Instructions are provided for the two most popular shells on Linux and Solaris. If you are using other shells, see the tutorial on setting the PATH variable.

Bash shell

Edit the startup file (~/.bashrc)

  1. Change a variable PATH variable
    PATH=/usr/local/jdk1.8.0/bin:$PATH
    export PATH
  2. Download the startup file
    %. /.profile

  3. % java -version
C shell (csh)

Edit the startup file (~/.cshrc)

  1. Set the path
    set path=(/usr/local/jdk1.8.0/bin $path)
  2. Save changes and close window
  3. Download the startup file
    % source ~/.cshrc
  4. Make sure the path is set by repeating the java command
    % java -version

Good afternoon, dear readers and guests of the blog, today I want to discuss with you this topic: what are Windows environment variables, where can they be used, both in normal user practice and in the practice of a system administrator, I will give you a few examples. How this whole thing is configured and changed to suit your needs, in my opinion, this is fundamental knowledge, the understanding of which will better show you the principle of operation of operating systems of the Windows family.

What are windows environment variables

Let's understand the concept, and so environment variable (environment variable) these are a special kind of links of reduced size to certain objects of the Windows operating system, used by different programs to store information and interact with it. An analogy can be drawn with relative links on sites where there is no explicit indication of the protocol. Most often these are paths to specific directories in the OS.

Where are Windows environment variables used?

Let me give you a few examples:

  • In scripts > when, for example, each user needs to make some kind of setting, for example, put a new folder with documents on the desktop. Since each user has their own path to the desktop, like C:\Users\lacky\Desktop, and you can also access the relative path using the %HOMEPATH% variable, if you enter %HOMEPATH%\Desktop in Explorer, you will be taken to the desktop current user's table.

  • in Group Policy, to configure user environments, such as roaming profiles.
  • Code optimization > If your code very often uses the same file or folder paths, as well as registry keys, you can easily assign a short variable for further use. Below I will give you a summary list of environment variables in Windows 10 and previous versions, and I will also show you how to create and change them.

All environment variables of Windows 10 and other versions include special operator%. It is necessary so that the operating system can process the search request. A simple example: you are looking for the TEMP folder and do not know where it is located, enter %TEMP% and the search will be on all local drives and partitions.

List of Windows 10 environment variables

The above list is fully suitable for both Windows 7 and Windows 8.1, everything has been personally verified. I am sure that this knowledge will greatly help you optimize your work.

  • %ALLUSERSPROFILE% > this variable will send you to the C:\ProgramData folder
  • %windir% > this is the C:\Windows folder
  • %APPDATA% > you are in the hidden folder C:\Users\Username\AppData\Roaming
  • %CommonProgramFiles% > folder C:\Program Files\Common Files
  • %CommonProgramFiles(x86)% > will take you to C:\Program Files (x86)\Common Files
  • %CommonProgramW6432% > will redirect you to C:\Program Files\Common Files
  • %COMPUTERNAME% > Computer_name, used in scripts
  • %ComSpec%> will open the Windows 10 Command Prompt C:\Windows\system32\cmd.exe
  • %HOMEDRIVE% > path to drive C:
  • %HOMEPATH% > this windows environment variable will take you to the user folder \Users\Username
  • %LOCALAPPDATA% > this windows environment variable will take you to the folder C:\Users\Username\AppData\Local
  • %LOGONSERVER% > ComputerName
  • %NUMBER_OF_PROCESSORS% > Number_of_processors
  • %OS% > Windows_NT, also used in scripts
  • %Path% > C:\Windows\system32;C:\Windows;C:\Windows\System32Wbem;
  • %PATHEXT% .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
  • %PROCESSOR_ARCHITECTURE% > x86 or AMD64, Windows architecture
  • %PROCESSOR_IDENTIFIER% > Intel64 Family 6 Model 37 Stepping 5, GenuineIntel
  • %PROCESSOR_LEVEL% > 6
  • %PROCESSOR_REVISION% > 2505 (example)
  • %ProgramData% > folder C:\ProgramData
  • %ProgramFiles% > C:\Program Files
  • %ProgramFiles(x86)% > folder C:\Program Files (x86)
  • %ProgramW6432% > C:\Program Files
  • %PROMPT% > $P$G
  • %PSModulePath% > C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ agree very quickly
  • %PUBLIC% > C:\Users\Public
  • %SystemDrive% > drive C:
  • %SystemRoot% > C:\Windows
  • %TEMP% >
  • %TMP% > C:\Users\Username\AppData\Local\Temp (default)
  • %USERDOMAIN% > ComputerName
  • %USERDOMAIN_ROAMINGPROFILE% > ComputerName
  • %USERNAME% > Username
  • %USERPROFILE% > C:\Users\Username

How to list all Windows variables

In Windows 10 and other versions, you can display a list of all Windows environment variables by opening a command prompt as an administrator and entering the SET command. As a result, you will get all the default Windows 10 environment variables for a specific operating system.

For convenience, you can export this entire list to a text file, to do this, enter:

set > D:\Variables.txt

Here are the contents of this document.

Another method to view operating system variables is the Windows registry. Press WIN+R and enter regedit. In the Registry Editor window that opens, go to the branch:

To view variables for the computer

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

To view variables for a user

HKEY_CURRENT_USER\Environment

Create Windows 10 environment variables

In addition to existing Windows 10 variables, you can create new ones, this is very easy and is not prohibited. What is required of you, you need to go to the system properties. There are several methods, if we are talking about Windows 10, then you can do it by right-clicking on the “Start” button, selecting System.

A universal method is to go to the properties of my computer or press the key combination WIN+Pause Breake.

From the system properties window, you should go to "Advanced system settings"

And here are two types of Windows environment variables:

  • Temporary variables temp
  • System Variables

Both can be easily modified or created.

For example, I will create a new system variable, call it SYSPREP and specify the path to the folder C:\Windows\System32\Sysprep

As you can see, there is nothing complicated here; thanks to things like this, you can greatly simplify your life and save a lot of time.

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!

An environment variable in Windows stores information about OS settings and user data. It is indicated using a paired symbol «%» , For example:

Using these variables, you can transfer the necessary information to the operating system. For example, %PATH% stores a list of directories in which Windows searches for executable files if the path to them is not explicitly specified. %TEMP% stores temporary files and %APPDATA%— user program settings.

Changing environment variables may help if you want to move the folder "Temp" or "AppData" to another place. Editing %PATH% will allow you to run programs from "Command line" without specifying a long path to the file each time. Let's look at methods that will help achieve these goals.

Method 1: Computer Properties

As an example of a program that needs to be launched, we use . Trying to activate this application from "Command line", you will get this error:

This happens because you did not specify the full path to the executable file. In our case, the full path looks like this:

"C:\Program Files (x86)\Skype\Phone\Skype.exe"

To avoid repeating this every time, let's add the Skype directory to the variable %PATH%.


Ready! Now you can run any program, not just Skype, from any directory in "Command line".

Method 2: "Command Line"

Consider the case when we want to set %APPDATA% to disk "D". This variable is missing in "Environment Variables", so it cannot be changed in the first way.


Changing the values ​​of environment variables requires some knowledge in this area. Do not play with the values ​​and do not edit them at random, so as not to harm the OS. Study the theoretical material well, and only after that proceed to practice.

Loading...