Add path environment variables in windows 7. Windows Environment Variables

Good afternoon, dear readers and guests of the blog, today I want to discuss with you this topic, what are variables Windows environment, where they can be used, both in the user's normal practice and in practice system administrator, I'll 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 operating objects Windows systems, used different programs for storing information and interacting 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 it on the desktop new folder with documents. 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.

  • V group policy, for setting up 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 Windows 10 environment variables and previous versions, and I’ll also show you how to create and change them.

All environment variables of Windows 10 and other versions include special operator%. It is necessary to operating system could process search query. A simple example: you are looking for the TEMP folder and don’t know where it is located, enter %TEMP% and the search will be on all local disks and sections.

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 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 " Extra options systems"

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.

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 graphical Windows interface. 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 batch file, the added folders will be in PATH only while it is running).

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")

Try entering in the Run window (Win + R) wmplayer and press Enter - Windows will open Media Player. 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 Windows folders and System32 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 V graphical interface . 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 programs Windows from the Run window, but not from the command line. Besides the player Windows Media, 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

This registry key can be used to quick launch programs whose shortcuts you do not need in the taskbar or on the desktop. For example, to search and replace in 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 going without for a long time UAC request, thanks to running the command line from the task scheduler. Having created a subsection cmda.exe, I specified in it the path to batch file performing 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, old way autoexec.bat still works, allowing you to run executable files without specifying a 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 specified explicitly. %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 receive 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.

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 click on the icon Computer.
  2. IN 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 the rest open windows, pressing 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 java version is the first one found in the 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


Loading...
Top