删除环境变量不起作用 [英] Deleting environment variables doesn't work
问题描述
为什么在Windows 7 Professional中使用 reg delete HKCU \ Environment/F/V TestVar
删除环境变量会将其从注册表中删除,但是该变量仍然存在?
Why deleting an environment variable with reg delete HKCU\Environment /F /V TestVar
in Windows 7 Professional removes it from the registry, but the variable still exists?
这是详细信息:我创建了以下3个 .cmd
文件:
Here are the details: I created the following 3 .cmd
files:
检查variable.cmd
echo TestVar = %TestVar%
pause
设置variable.cmd
setx TestVar 123
pause
删除variable.cmd
reg delete HKCU\Environment /F /V TestVar
pause
然后,我按照以下步骤操作(双击以确保每次都启动一个新的会话):
Then I follow these steps (double clicking to make sure that I start a new session every time):
- 双击
Check variable.cmd
,我发现TestVar
不存在 - 双击
Set variable.cmd
,它说SUCCESS:已保存指定的值.
- 双击
Check variable.cmd
,它会显示变量值.好! - 双击
Delete variable.cmd
,它显示操作成功完成.
- 双击
Check variable.cmd
,它仍然显示变量值.不好!</li> - 单击开始"菜单,键入"
环境
",然后单击"编辑您的帐户的环境变量"
以打开"环境变量
"对话框,然后单击确定".确定
,无需进行任何更改 - 双击
Check variable.cmd
,该变量不再存在
- Double click on
Check variable.cmd
and I see thatTestVar
does not exist - Double click on
Set variable.cmd
and it saysSUCCESS: Specified value was saved.
- Double click on
Check variable.cmd
and it shows the variable value. Good! - Double click on
Delete variable.cmd
and it saysThe operation completed successfully.
- Double click on
Check variable.cmd
and it still shows the variable value. Bad! - Click on the Start menu, type
environment
, click onEdit environment variables for your account
to open theEnvironment Variables
dialog box, clickOK
without changing anything - Double click on
Check variable.cmd
and the variable does not exist anymore
我可以在第2步之后在注册表中找到该值,但在第4步之后找不到它,但是在第5步仍然可以找到它.即使我什么都没做,步骤6仍会真正删除该变量.
I can find the value in the registry after step 2, I cannot find it after step 4, but step 5 still finds it. And even if I don't change anything, step 6 really deletes the variable.
推荐答案
这是我的问题的解决方案.我不知道这是否是正确的解决方案,但它对我有用:
Here is the solution to my problem. I don't know if it is the correct solution, but it works for me:
检查variable.cmd
set TestVar
@pause
设置variable.cmd
setx TestVar 123
@pause
删除variable.cmd
reg delete HKCU\Environment /F /V TestVar
setx DummyVarUsedToDelete ""
reg delete HKCU\Environment /F /V DummyVarUsedToDelete
@pause
setx
cannot be used to delete a variable, as explained here, but it does the missing broadcasting after a variable has been removed from the registry with reg delete
.
编辑
我添加了一行以从注册表中删除 DummyVarUsedToDelete
.这将不会广播,但这是一个暂时的小问题.
I added a line to delete the DummyVarUsedToDelete
from the registry. This will not be broadcasted, but it is a small temporary problem.
这篇关于删除环境变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!