简体   繁体   English

为什么Windows的“路径”环境变量和命令行不同?

[英]Why are “Path” Windows's environment variable and the command line different?

On my Pc, running Windows XP 5.1.2600, following 在我的PC上,运行Windows XP 5.1.2600,如下

"My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path" “我的电脑”>“属性”>“高级”>“环境变量”>“路径”

I get a string, but in a batch file, or directly typing from prompt, by means of 我得到一个字符串,但是在批处理文件中,或者通过以下方式直接从提示符键入

echo %path% 回声%路径%

I get a different one. 我得到了另一个。

Can someone, please, explain what makes them differ and how to fix the issue, setting the "DOS-path" to the same value of "Windows-PATH" ? 有人可以解释一下它们与众不同的原因以及如何解决此问题,将“ DOS-path”设置为“ Windows-PATH”的相同值吗?

Two things: 两件事情:

  1. As others have mentioned, the full value of PATH is the combination of the user's PATH variable and the system's PATH variable. 就像其他人提到的那样, PATH的完整值是用户的PATH变量和系统的PATH变量的组合。

  2. If you change environment variables (including PATH ), any processes already running (including the Command Prompt) will continue using the old environment variable values. 如果更改环境变量(包括PATH ),则任何已在运行的进程(包括命令提示符)将继续使用旧的环境变量值。 You will need to restart those processes to pick up any changes that you've made. 您将需要重新启动这些过程以获取所做的任何更改。

Probably the difference you are seeing is that when a new process is made, its default environment contains a PATH variable that is made by merging the system variable with the user variable. 您可能看到的区别是,在创建新进程时,其默认环境包含一个PATH变量,该变量是通过将系统变量与用户变量合并而成的。

As for how to "fix the issue", there is nothing to fix. 至于如何“解决问题”,没有什么可以解决的。 The system behaves as designed. 系统按设计运行。

The value of the PATH environment variable you see on the command line (which has nothing to do with "DOS" btw) is the sum of the system wide PATH variable and the user specific PATH variable. 您在命令行上看到的PATH环境变量的值(与“ DOS” btw无关)是系统范围的PATH变量和用户特定的PATH变量的和。

If you open the dialog with the system variables from within the control panel, the upper part contains the user specific environment variables. 如果从控制面板中打开带有系统变量的对话框,则上部将包含用户特定的环境变量。 The lower part contains the system variables. 下部包含系统变量。

If you set a PATH variable for your user to eg c:\\foo , and the system path is be c:\\Windows\\System32 then you'd see c:\\Windows\\System32;c:\\foo when you do an ECHO %PATH% on the commandline. 如果将用户的PATH变量设置为c:\\foo ,并且系统路径为c:\\Windows\\System32那么在执行ECHO %PATH%时会看到c:\\Windows\\System32;c:\\foo命令行上的ECHO %PATH%

I was getting the same issue where the System Variable that I get through the 我遇到了相同的问题,即我通过

"My Computer" > "Properties" > "Advanced" > "Environment Variables" > "Path" “我的电脑”>“属性”>“高级”>“环境变量”>“路径”

was different that the one being displayed through the command line interface via 与通过命令行界面通过

ECHO %PATH% 回声%PATH%

The fix for this is basically to wait for the change to take place and this can be made faster by restarting the cmd and explorer. 解决此问题的方法基本上是等待更改发生,并且可以通过重新启动cmd和资源管理器来使其更快。 To do that you can simply end task for Explorer and CMD and then start a new task or restart it directly. 为此,您只需结束Explorer和CMD的任务,然后启动新任务或直接重新启动它即可。

在此处输入图片说明

The same shall be done for the CMD as well. 对于CMD也应执行相同的操作。

The Windows registry can hold path entries that do not show up in the Environment Variables version of PATH you see via the control panel. Windows注册表可以包含未在通过控制面板看到的PATH的“环境变量”版本中显示的路径条目。 (Why, I do not know). (为什么,我不知道)。

The difference means that something (likely an install script) made changes to the registry. 差异意味着某些内容(可能是安装脚本)对注册表进行了更改。

To view or change the local user's path variable, look in the HKEY_CURRENT_USER\\Environment key. 要查看或更改本地用户的路径变量,请查看HKEY_CURRENT_USER\\Environment键。

To view the system path, look in HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment 要查看系统路径,请查看HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM