有人可以解释这个结果吗?
设置路径后,它没有改变.这是在管理员命令行中运行的:
C:\Windows\system32>setx path "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin" SUCCESS: Specified value was saved. C:\Windows\system32>path PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;D:\Program Files (x86)\Metapad36;D:\Program Files (x86)\Metapad36" /M
我已经读过用户的机器PATH变量的%PATH%= PATH变量.我看到机器路径Admin的路径了吗?
看过关于这个话题的其他文章,但仍然困惑.
我应该清除用户路径,所以没有重复吗?
更新:重新提示“此工具创建或修改的变量将在以后的命令窗口中可用”我打开一个非管理员窗口并输入:
>path PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;;D:\Program Files (x86)\Metapad36;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin
路径重复两次.好的,然后在相同的提示我设置路径没有重复,没有/ M:
>setx path "C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin" SUCCESS: Specified value was saved.
显然保存在当前用户环境中.
然后我打开一个新的非管理命令窗口,并:
>path PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;;D:\Program Files (x86)\Metapad36;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin`
它没有改变.为什么?
在Windows中,每个进程都获得一个环境副本,该环境本质上是进程启动时全局环境的快照.进程运行时对全局环境的更改不会传播回进程自己的环境副本.
要回答实际问题,setx会修改用户环境(如果使用/ M运行,则会修改系统),但在执行setx的进程中不会立即看到更改,在本例中为cmd.exe.如果在运行setx后打开新的命令提示符,则会在该cmd.exe实例中看到更改.
这在setx /中明确指出.救命:
On a local system,variables created or modified by this tool will be available in future command windows but not in the current CMD.exe command window.
要在全局环境和当前进程中实现相同的更改,您需要同时运行setx和set.