删除环境变量不起作用 [英] Deleting environment variables doesn't work

查看:43
本文介绍了删除环境变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在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):

  1. 双击 Check variable.cmd ,我发现 TestVar 不存在
  2. 双击 Set variable.cmd ,它说 SUCCESS:已保存指定的值.
  3. 双击 Check variable.cmd ,它会显示变量值.好!
  4. 双击 Delete variable.cmd ,它显示操作成功完成.
  5. 双击 Check variable.cmd ,它仍然显示变量值.不好!<​​/li>
  6. 单击开始"菜单,键入"环境",然后单击"编辑您的帐户的环境变量" 以打开"环境变量"对话框,然后单击确定".确定,无需进行任何更改
  7. 双击 Check variable.cmd ,该变量不再存在
  1. Double click on Check variable.cmd and I see that TestVar does not exist
  2. Double click on Set variable.cmd and it says SUCCESS: Specified value was saved.
  3. Double click on Check variable.cmd and it shows the variable value. Good!
  4. Double click on Delete variable.cmd and it says The operation completed successfully.
  5. Double click on Check variable.cmd and it still shows the variable value. Bad!
  6. Click on the Start menu, type environment, click on Edit environment variables for your account to open the Environment Variables dialog box, click OK without changing anything
  7. 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 不能用于删除变量,如

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆