SET command - working with Windows environment variables. In some cases, when starting a program, you do not need to specify the full path to it System variable path windows 7

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 executable files, if the path to them is not specified explicitly. %TEMP% stores temporary files and %APPDATA%— user program settings.

Change 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.

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 a folder is added to PATH, executables can be run from 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 GUI Windows. 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")

Instructions

Right-click on the My Computer icon located on your desktop or Start menu. In the appeared context menu 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 an operating room Windows system 7, then also right-click on the “My Computer” icon, select “Properties”, then in the left side of the properties window select “ Extra options systems."

In the “System Properties” window, go to the “Advanced” tab by left-clicking on it - you will see three sections additional settings systems. 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 components operating system and application programs installed in it to obtain the addresses of directories in which executable files can be searched. 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, 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) in 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 your internet browser mobile phone Nokia to deliver 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 just find 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 can be performed by the user standard means operating room Microsoft systems Windows does not require any additional software third party developers.

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

    Team SET used to view and change environment variables in the command line Windows line. Environment variables are variables whose accepted values ​​characterize the environment in which the current program is running - paths system files, hardware information, user directories, etc. Environment variable values ​​are generated during the process Windows boot, user registration in the system, when executing individual processes or using a command SET. To view the value assumed by a specific variable, you can use the command:

SET variable
SET PATH- display the value of a variable PATH
To create a new variable or change the value of an existing one, use the command:

SET variable=string

variable- Environment variable name.
line- A character string assigned to the specified variable.

SET MyName=Vasya- set the value of a variable MyName

SET path=C:\progs;%path%- change the value of a variable PATH by adding to the beginning of the line C:\progs

The value accepted by the variable is available for processing in command files by using its name enclosed in percent signs - % . For example, a command to display text on the ECHO display in the form:

ECHO date- will display the word "date" and the command
ECHO %date% will display the value of the variable date, i.e. current date in operating system format.

Team SET without parameters is used to display the current values ​​of environment variables.

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Usr\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=TEST7
ComSpec=C:\windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Usr
LOCALAPPDATA=C:\Users\Usr\AppData\Local
LOGONSERVER=\\TEST7
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\windows\system32;C:\windows;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS; .VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 3 Stepping 4, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0304
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\windows\system32\Windows PowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SystemDrive=C:
SystemRoot=C:\windows
TEMP=C:\Users\Usr\AppData\Local\Temp
TMP=C:\Users\Usr\AppData\Local\Temp
USERDOMAIN=test7
USERNAME=Usr
USERPROFILE=C:\Users\Usr
windir=C:\windows

In addition to the variables displayed in the list when calling the SET command, there are others whose values ​​change dynamically:

%CD%- takes the value of the current directory.
%DATE%- takes the value of the current date.
%TIME%- takes the value of the current time.
%RANDOM%- meaning random number in the range between 0 and 32767.
%ERRORLEVEL%- the current value of ERRORLEVEL, a special variable that is used as an indication of the result of program execution.
%CMDEXTVERSION% CMD.EXE extended command processing version value.
%CMDCMDLINE%- expands to the original command line that called the shell.

If you specify only part of the name when calling the SET command, a list of variables whose names begin with the specified string will be displayed. For example:

SET U- will display the values ​​of all variables whose names begin with "U".

The SET command supports two additional switches:

SET /A expression

SET /P variable=

The /A switch specifies that the string to the right of the equals sign is a numeric expression whose value is being evaluated. The expression engine is very simple and supports the following operations, listed in descending order of priority:

When using any logical or binary operators, you must enclose the expression string in quotation marks. Any non-numeric strings in the expression are treated as environment variable names whose values ​​are converted to numeric form before use. If a variable with the specified name is not defined in the system, a null value is substituted instead. This allows you to perform arithmetic operations on environment variable values ​​without having to enter % signs to get the values. If SET /A is called from the command line rather than from a batch file, it prints the final value of the expression. The name of the environment variable must appear to the left of any assignment operator. Numeric values ​​are treated as decimal unless they are preceded by a prefix:

0x- for hexadecimal numbers
0 - for octal numbers.

Example of using prefixes:

SET /A REZ=0xA+012
ECHO %REZ%

In this batch file, the value of the variable is REZ is calculated by adding the number 10 represented in hexadecimal (0xA) and the number 10 represented in octal (012).

The /P switch allows you to set the value of a variable for the input string entered by the user. Shows the specified promptString prompt before reading the entered string. The promptString prompt may be empty. This key allows you to organize a dialogue with the user in a batch file:

@ECHO OFF
SET /P NAME=Enter username:
SET /P pass=Enter password:
ECHO Username - %NAME% , Password - %PASS%

In batch files, quite often you need to work with part of the value taken by a variable, for which you use substitution values:

variable:string1=string2- replaces in the received value of the variable line1 on line2

The following batch file uses the dot to dash character in the variable value corresponding to the current date:

@ECHO OFF
set tm=%DATE%
ECHO Date1 = %tm%
SET tm=%DATE:.=-%
ECHO Date2 = %tm%

To highlight part of the value taken by a variable, the following construction is used:

variable:~x,y- Where x- the number of skipped characters from the beginning of the line, and y- the number of characters used as the value of the variable.

The following example uses the display of the current time without seconds and fractions of seconds (only the first 5 characters from the standard value of the TIME variable):

@ECHO OFF
set tm=%TIME%
ECHO Time1 = %tm%
SET tm=%TIME:~0.5%
ECHO Time2 = %tm%

If the value y(length) is not specified, then the value of the variable remaining until the end of the line is used. If the value y is negative, then part of the variable value string from the end is used. The previous example can be modified to specify that the time value received is stripped 6 characters from the end:

@ECHO OFF
set tm=%TIME%
ECHO Time1 = %tm%
SET tm=%TIME:~0.-6%
ECHO Time2 = %tm%

It is possible to use the number of gaps is not specified, and a negative number is used, then the received value will be part of the variable from the end of the line:

%PATH:~-10%- will extract the last 10 characters of the PATH variable

You can omit the null value while maintaining the substitution format:

%PATH:~0.-2% equivalent %PATH:~,-2%

Using environment variables In batch files there is a certain limitation associated with the fact that the assigned value remains unchanged when it is modified within a group of commands specified by parentheses, for example in commands IF or FOR. To bypass this limitation, use the command processor launch with the /V:ON parameter and instead of percent signs, to obtain the received value variable, are used exclamation marks. In addition, it is possible to use the standard launch of the command processor, but with local activation of this mode with the command:

The difference in the results of using variable values ​​is quite clearly demonstrated by the following batch file:


@ECHO OFF
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo With percent sign=%VAR% , With question mark=!VAR!

Team set VAR=after executed inside a subroutine delimited by parentheses and, if the command is removed Setlocal EnableDelayedExpansion or not to use to get the value of a variable VAR exclamation marks, its value will remain the old one (what was set before entering the subroutine). A similar problem occurs when the value of a variable is changed within the command loop. FOR. For example, to get a list of files in the current directory, a batch file like this won't work:

set LIST=
for %%i in (*) do set LIST=%LIST% %%i
echo %LIST%

Variable value LIST will not be changed inside the loop. In order for this to happen, the batch file needs to be modified as follows:

Setlocal EnableDelayedExpansion
set LIST=
for %%i in (*) do set LIST=!LIST! %%i
echo %LIST%

Now, the value of the variable LIST inside a loop FOR will change, sequentially taking on the values ​​of file names separated by space ( set LIST=!LIST! %%i)




Top