【问题标题】:PATH environment variable is different in cmd and system properties [closed]cmd和系统属性中的PATH环境变量不同[关闭]
【发布时间】:2016-11-07 11:12:40
【问题描述】:

我的 PATH 环境变量有问题。如果我在系统属性中查看环境变量中的 PATH,我会得到这个(添加换行符以提高可读性):

C:\app\User\product\11.2.0\dbhome_1\bin;C:\Python34\;C:\Python34\Scripts;
C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Windows Live\Shared;C:\Program Files(x86)\CMake\bin;
C:\Program Files\Microsoft\Web PlatformInstaller\;
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;
C:\Program Files (x86)\Livestreamer;C:\Program Files (x86)\Git\cmd;
C:\MinGW\bin;C:\Program Files (x86)\Skype\Phone\;
C:\Program Files\Haskell Platform\7.10.3\mingw\bin;
C:\Program Files\Microsoft Network Monitor 3\;
C:\Program Files\Java\jdk1.8.0_20\bin;C:\Users\User\Anaconda3;
C:\Users\User\Anaconda3\Scripts;C:\Users\User\Anaconda3\Library\bin;
C:\Users\User\Anaconda\Lib\site-packages;C:\gradle\bin

但如果我用运行对话框打开 cmd 并写 PATH,我会得到:

PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Haskell\bin;C:\Program
 Files\Haskell Platform\7.10.3\lib\extralibs\bin;C:\Program Files\Haskell Platfo
rm\7.10.3\bin;C:\gurobi605\win64\bin;C:\Perl\site\bin;C:\Perl\bin;C:\app\User\pr
oduct\11.2.0\dbhome_1\bin;C:\Python34\;C:\Python34\Scripts;C:\Program Files\Comm
on Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Micro
soft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem
;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live
\Shared;C:\Program Files(x86)\CMake\bin;C:\Program Files\Microsoft\Web Platform
Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\P
rogram Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program File
s (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\Microsoft SQL Serv
er\120\DTS\Binn\;C:\Program Files (x86)\Livestreamer;C:\Users\User\AppData\Roami
ng\npm;C:\Program Files (x86)\Git\cmd;C:\MinGW\bin;C:\Program Files\Microsoft SQ
L Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\1
10\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Fi
les (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files
 (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Skype\Phone\;
C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Haskell Platform\
7.10.3\mingw\bin;C:\Program Files\Microsoft Network Monitor 3\

我可以以某种方式使它们相同吗?我需要使用系统属性中的 PATH,而不是命令行中的。

我尝试使用set PATH="(new path)" 更改命令行中的路径,但这只是暂时更改它。如果我关闭并打开一个新的控制台窗口,它会返回。

我也试过setx PATH "(new path)",但也没有任何改变。

我使用的是 64 位 Windows 7 家庭高级版

【问题讨论】:

  • 您是在问它们的内容是否不同,或者如何在 CMD 中的分号后添加换行符?
  • 我想知道如何使它们相同。无法弄清楚如何永久更改 cmd PATH。帖子里有提到。反正已经解决了。
  • 不明白为什么这个问题被标记为离题。系统变量经常涉及到编程。

标签: windows path environment-variables


【解决方案1】:

这是因为变量 PATH 有不同的作用域,因此可以有不同的内容。这些范围是usermachinesetx 设置用户变量 (HKEY_CURRENT_USER) 但如果添加开关 /m 那么这些变量将在系统范围内设置 (HKEY_LOCAL_MACHINE)。

系统属性显示user 范围内的变量内容,而echo %PATH% 显示系统范围的内容。

如果您想在两者中永久拥有相同的内容,您可以按照here 的描述使用 PowerShell。

【讨论】:

  • 我刚刚在 powershell 中尝试了“$env:Path = (path I want)”,就像链接说的那样,但是我在 cmd 中看到的路径没有改变。我设置了系统路径还是用户路径?如何设置另一个?
  • 它似乎只是改变了用户路径。我通过注册表更改了系统路径。
  • [Environment]::SetEnvironmentVariable( "Path", "<your new Path Value goes here", "Machine" ) 用于系统范围的设置,[Environment]::SetEnvironmentVariable( "Path", "<your new Path Value goes here", "User" ) 用于用户设置。
【解决方案2】:

Windows 中有两种类型的变量。用户变量和系统变量。您可以查看和编辑它。打开系统属性,打开高级选项卡,单击环境变量按钮。刚刚补充说你需要正确的变量区域。

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 2021-09-18
    • 2010-10-07
    • 1970-01-01
    • 2020-04-03
    • 2023-03-31
    • 2011-02-21
    • 1970-01-01
    相关资源
    最近更新 更多