本文介绍了从OS级别配置中删除环境变量的命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Windows有 setx
命令
Windows has setx
command
Description:
Creates or modifies environment variables in the user or system
environment.
所以你可以设置一个这样的变量
So you can set a variable like this
setx FOOBAR 1
,您可以清除像这个
setx FOOBAR ""
但是,该变量不会被删除,它保留在注册表中
However, the variable does not get removed, it stays in the registry
那么你如何实际删除变量?
So how would you actually remove the variable?
推荐答案
当前环境(永久不)
To remove the variable from the current environment (not permanently):
set FOOBAR=
要永久删除用户环境中的变量(这是默认位置 setx
put it):
To permanently remove the variable from the user environment (which is the default place setx
puts it):
REG delete HKCU\Environment /F /V FOOBAR
如果变量设置在系统环境中(例如,如果您最初设置为 setx / M
),则以管理员身份运行:
If the variable is set in the system environment (e.g. if you originally set it with setx /M
), as an administrator run:
REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /F /V FOOBAR
这篇关于从OS级别配置中删除环境变量的命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!