Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
哪个Windows注册表项存储PATH变量?_Windows_Powershell_Path_Registry_Regedit - Fatal编程技术网

哪个Windows注册表项存储PATH变量?

哪个Windows注册表项存储PATH变量?,windows,powershell,path,registry,regedit,Windows,Powershell,Path,Registry,Regedit,脚本需要将程序添加到Windows路径。另一个脚本需要从Windows路径中删除相同的程序。对于兼容性问题,脚本需要在大多数(如果不是所有的话)Windows上运行 哪些注册表项(或多个注册表项)在各种Windows计算机类型上一致地存储路径 例如,在我的Windows 10 Home Edition笔记本电脑上,路径存储在以下键的PATH属性中: HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 但另一个用户

脚本需要将程序添加到Windows路径。另一个脚本需要从Windows路径中删除相同的程序。对于兼容性问题,脚本需要在大多数(如果不是所有的话)Windows上运行

哪些注册表项(或多个注册表项)在各种Windows计算机类型上一致地存储路径

例如,在我的Windows 10 Home Edition笔记本电脑上,路径存储在以下键的
PATH
属性中:

HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
但另一个用户通知我,此密钥在其Windows计算机上不可用

那么,关键位置可能性的完整列表是什么


请注意,脚本直接以键为目标,因为对路径的更改必须在运行时结束后保持不变。其他方法似乎只是在程序运行时临时更改路径

在PowerShell中,使用以下命令持续设置
路径
环境:

要删除环境变量,请将环境变量值设置为
$null

[Environment]::SetEnvironmentVariable( 'VARIABLE_NAME', $null, [EnvironmentVariableTarget]::Machine )
至于为什么你的用户丢失了注册表项?这听起来像是一个更大的问题,因为
HKEY\U LOCAL\U MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
是存储和检索系统环境变量的地方。从XP开始就一直是这样的

如果某个人的机器上缺少该密钥,我敢打赌,该用户不是找不到正确的位置,就是某种恶意软件可能是原因


如果要按照注释中的要求在流程级别设置环境变量,可以使用
$env:
变量在流程级别读取和设置环境变量:

$env:VARIABLE_NAME = 'VALUE'

HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
对于Win XP直到服务器2012 R2、Win10 Enterprise、Win10 Prot这可能会有帮助。您能否演示如何临时设置PATH变量,因此,除了永久可用之外,它还可以在同一会话中立即可用?这很简单,
$env:VARIABLE\u NAME='VALUE'
。这将在流程级别设置环境变量,以便当前流程和子流程能够看到该变量。
$env:VARIABLE_NAME = 'VALUE'