使用 powershell 将路径永久添加到 Windows 似乎不起作用 [英] Adding path permanently to windows using powershell doesn't appear to work
问题描述
我遵循 这个程序 以使用 powershell 永久添加 SumatraPDF 的路径.链接中的最后几个命令用于检查是否确实添加了路径.
I followed this procedure in order to permanently add a path to SumatraPDF using powershell. The last few commands from the link are meant to check that the path has indeed been added.
当我使用以下命令访问路径时,
When I access the path using the following command,
(get-itemproperty -path 'Registry::HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession ManagerEnvironment' -Name PATH).Path.split(';')
结果包括 SumatraPDF 的路径
the result includes the path to SumatraPDF
C:Windowssystem32
C:Windows
C:WindowsSystem32Wbem
C:WindowsSystem32WindowsPowerShellv1.0
C:WindowsSystem32OpenSSH
C:ProgramDatachocolateyin
C: exlive2021inwin32
C:Users921479AppDataLocalSumatraPDF
但是,当我使用以下命令访问它时,
However when I access it using the following command,
($env:path).split(';')
结果不包含 SumatraPDF 的路径:
the result does not contain the path to SumatraPDF:
C:Windowssystem32
C:Windows
C:WindowsSystem32Wbem
C:WindowsSystem32WindowsPowerShellv1.0
C:WindowsSystem32OpenSSH
C:ProgramDatachocolateyin
C: exlive2021inwin32
C:Users921479AppDataLocalMicrosoftWindowsApps
最后,实际上传递 sumatrapdf
不起作用,这表明真正的路径是使用 get-itemproperty
命令访问的路径.
Finally, actually passing sumatrapdf
does not works, which indicates to me that the real path is the one accessed using the get-itemproperty
command.
为什么注册表中设置的路径与$env:path
中设置的路径不对应?链接 我关注了?我该如何纠正?
Why does the path set in the registry not correspond to the one set in $env:path
? Is there a mistake in the procedure shown in the link I followed? How can I correct it?
我应该提一下,我已经尝试过重新启动 shell,但它没有帮助.
I should mention I have already tried restarting the shell but it doesn't help.
推荐答案
使用 setx 永久更新环境变量.不要破解注册表.
Use setx to permanently update an environment variable. Don't hack the registry.
调用 setx 后,只需在当前会话中手动更新 Path 环境即可.Powershell:在 PowerShell 中重新加载路径
After you invoke setx, just update the Path environment manually in the current session. Powershell: Reload the path in PowerShell
这篇关于使用 powershell 将路径永久添加到 Windows 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!