Analysis of Windows System environment variables

Source: Internet
Author: User

What is the environment variable, want to know the precise official definition, can direct Baidu. Here, I just want to talk about my understanding of it.

First, the demand for environmental variables proposed

Assume that there is an executable "Hi.exe" on the D drive,

If you want to start in the console, and the current location is C:\Users\lenovo, then type Hi.exe directly (you can enter Hi, omit ". exe"), will the program start?

Will find that the program does not start, and that "Hi.exe is not an internal or external command, is not a running program or batch file," why this, in fact, because in the current directory, can not find hi.exe this file.

So, in order to start the program, we have to switch to the D drive and then type Hi.exe, so ...

The program starts normally and prints out the "Hello world! ”。

While we're happy with the results, we're going to ask the question that it's a hassle to switch to the directory where the files are located every time. Is there a way that we can start a program in any location just by typing Hi.exe?

Fortunately, the developers of the system are aware of the problem, and they are given a set of solutions. In this package, environment variables turned out. Just to configure the environment variables, the above problems can be easily resolved.


Second, how to configure environment variables

So, the question is, how do you configure the environment variables? Here are 2 ways to do this.

① is configured in the computer's properties (once and for all, that is, it only needs to be configured this time and can be used later).

A. Right-click on the desktop computer icon to pop up a menu and select "Properties";

B. In the left Control Panel home page, select "Advanced System Settings";

C. Select "Environment variable" in the pop-up system Properties window;

D. Locate the "Path" item in the Popup environment variable window, select and click Edit;

E. At the top of the directory where the files are added, and add semicolons separated from the following content, click OK, the environment variables are configured.

The ② is configured under the console with the "Set path" command (temporary, the console shuts down and reverts to pre-configuration state).

The following%path% indicates that the original path configuration was obtained, and the entire representation was added "d:\;" on the basis of the original configuration.


Third, the test requirements are satisfied

OK, the environment variable is well-configured, now try to start the program easily and conveniently.

Pleasantly surprised to find that in the C, D, E, F disk only need to type Hi.exe can start the program. Are you happy?!


Four, the current directory and environment variable configuration of the directory is the first

Originally written to the above can be finished, because the purpose has been achieved, but since the writing, and then go one step further, to explore the current directory and environment variable configuration of the directory which is the first question. What do you mean?

For example, I now have two files of the same name "Test.exe", respectively, in the e-disk and the F-disk, e-disk program output "This is the environment variable configuration directory of the file!" ", program output of F-Disk" This is the file of the current directory! ”。 Assuming that the environment variable is now configured as "e:\;%path%" and switched to the F-disk, which program will be started if you type Test.exe? The e-drive or the F-drive program?

Through the results, we can see that the starting is the F-disk (current directory) of the program.

At this point, what happens if I delete the Test.exe file under the F-disk?

Through the results, you can see that the startup is the E-disk (environment variable configuration directory) program.

Summary: When starting a program, the current directory will be found in the program file, if there is a direct execution; otherwise, go to the environment variable configuration directory to find whether the file exists, there is the execution.



Analysis of Windows System environment variables

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.