In Windows, how does one view, modify, delete, and add environment variables in the cmd command line?

Source: Internet
Author: User

First, make it clear:

All modifications to environment variables under the cmd command line are onlyCurrent windowValid, not permanent modification. That is to say, when the cmd command line window is closed, it will no longer work. There are two ways to permanently modify environment variables: one is to directly modify the Registry (this method has not been tested yet), and the other is through my computer-> properties-> advanced, to set system environment variables (View Details ).

Next, clarify the role of environment variables.

It is a parameter used by the operating system to specify the runtime environment. For example, the Temporary Folder location and the system folder location. When you run some programs, in addition to searching in the current folder, you will also search for these environment variables. For example, "Path" is a variable, it stores directory paths for some common commands.

Third: under what circumstances?

When a command is called in the cmd command line window, "xxx is not an internal or external command, or a program or batch file that can be run" is often displayed ", if your spelling is correct and the program exists in the computer, the prompt is that your path variable is not correctly set because your path, that is, your program does not exist in the default path, and you have not given the absolute path of your program (because you just entered the command or program name ), this problem occurs when the operating system does not know where to find your program.

Fourth: how to modify it?

1,View all currently available Environment Variables: Enter set.

2,View an environment variable: Enter"Set variable name". For example, if you want to view the value of the path variable, enter set path.

3,Modify Environment Variables: Enter "set variable name = variable content". For example, if you set path to "d: \ nmake.exe", enter set path = "d: \ nmake.exe ". Note that this environment variable is used to overwrite the previous content, rather than append the content. For example, after setting the path above, if I re-enter set path = "c" and view the path again, the value is "c :", instead of "d: \ nmake.exe" and "c ".

4,Set to null: To set a variable to null, enter "set variable name =. For example, "set path =" is empty when you view the path. Note: As mentioned above, it only works in the current command line window. Therefore, when viewing the path, do not right-click "my computer" -- "attribute "........

5,Append content to a variable(Unlike 3, which is overwrite): Enter "set variable name = % variable name %; variable content ". For example, to add a new path to path, enter "set path = % path %; d: \ nmake.exe" to add d: \ nmake.exe to path, execute "set path = % path %; c:" again. Then, when you use the set path statement to view it, there will be: d: \ nmake.exe; c :, instead of c :.

 

Appendix: some common environment variables and their functions are attached below.

% ALLUSERSPROFILE % returns all "user configuration files.

% APPDATA % partial return the location where the application stores data by default.

% CD % returns the current directory string.

% CMDCMDLINE % returns the exact command line used to start the current Cmd.exe.

% CMDEXTVERSION % The system returns the version number of the current "command handler extension.

% COMPUTERNAME % the name of the computer returned by the system.

% COMSPEC % The system returns the exact path of the executable program of the command line interpreter.

% DATE % The system returns the current DATE. Use the same format as the date/t command. Generated by Cmd.exe. For more information about the date command, see Date.

% ERRORLEVEL % The system returns the error code of the recently used command. A non-zero value is usually used to indicate an error.

% HOMEDRIVE % The system returns the local workstation drive letter that is connected to the user's home directory. Set Based on the main directory value. The user home directory is specified in "local users and groups.

% HOMEPATH % The system returns the complete path of the user's home directory. Set Based on the main directory value. The user home directory is specified in "local users and groups.

% HOMESHARE % The system returns the network path of the user's shared home directory. Set Based on the main directory value. The user home directory is specified in "local users and groups.

% LOGONSEVER % returns the name of the domain controller that verifies the current logon session.

% NUMBER_OF_PROCESSORS % Number of processors installed on the computer.

% OS % The system returns the name of the operating system. Windows 2000 displays the operating system as Windows_NT.

% PATH % The system specifies the search PATH of the executable file.

% PATHEXT % The system returns a list of file extensions that the operating system deems executable.

% PROCESSOR_ARCHITECTURE % The system returns the processor's chip architecture. Value: x86 and IA64.

% PROCESSOR_IDENTFIER % The system returns the processor description.

% PROCESSOR_LEVEL % The system returns the model of the processor installed on the computer.

% PROCESSOR_REVISION % The system returns the system variable of the processor revision number.

% PROMPT % returns the command PROMPT settings of the current interpreter. Generated by Cmd.exe.

% RANDOM % The system returns any decimal number between 0 and 32767. Generated by Cmd.exe.

% SYSTEMDRIVE % The system returns a drive containing the Windows XP root directory (that is, the system root directory.

% SYSTEMROOT % The system returns the location of the Windows XP root directory.

% TEMP % and % TMP % the system and user return the default temporary directory used by the applications available to the current login user. Some applications require TEMP, while other applications require TMP.

% TIME % The system returns the current TIME. Use the same format as the time/t command. Generated by Cmd.exe. For more information about the time command, see Time.

% USERDOMAIN % partial return the name of the domain containing the user account.

% USERNAME % returns the name of the user currently logged on.

% UserProfile % returns the location of the configuration file of the current user.

% WINDIR % the location of the operating system directory returned by the system.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.