windows 无法使用 VBS 删除注册表项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7070843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't delete registry key using VBS
提问by Di Zou
I am trying to delete a registry key. Here is my code:
我正在尝试删除注册表项。这是我的代码:
Option Explicit
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
Dim strDelete
strDelete = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\test\")
WScript.echo(strDelete)
objShell.RegDelete "HKEY_LOCAL_MACHINE\SOFTWARE\test\"
WScript.Quit
When I run this, I get this output:
当我运行这个时,我得到这个输出:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.test
N:\RogueDevelopment\test.vbs(23, 1) WshShell.RegDelete: Invalid root in registry key "HKEY_LOCAL_MACHINE\SOFTWARE\test\".
Microsoft (R) Windows Script Host 版本 5.8
版权所有 (C) Microsoft Corporation。版权所有。test
N:\RogueDevelopment\test.vbs(23, 1) WshShell.RegDelete:注册表项“HKEY_LOCAL_MACHINE\SOFTWARE\test\”中的根无效。
My registry key is located at "HKEY_LOCAL_MACHINE\SOFTWARE\test\" and it has a default value of "test". The value in the key is being read correctly, but the key cannot be deleted. I am running this script on Windows 7. Why is this happening?
我的注册表项位于“HKEY_LOCAL_MACHINE\SOFTWARE\test\”,它的默认值为“test”。正在正确读取密钥中的值,但无法删除密钥。我在 Windows 7 上运行此脚本。为什么会发生这种情况?
采纳答案by Neil
You don't have permission to open HKEY_LOCAL_MACHINE\SOFTWARE\test\
for delete access. If you really need to modify keys under HKLM, you will need to elevate your process.
您无权打开HKEY_LOCAL_MACHINE\SOFTWARE\test\
删除权限。如果您确实需要在 HKLM 下修改密钥,则需要提升您的流程。