vbscript - VBS RegRead 不返回值

标签 vbscript registry

我有以下代码:

Dim objShell,failing_path,working_path

failing_path = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test"
working_path = "HKEY_LOCAL_MACHINE\SOFTWARE\7-zip\Path"

Set objShell = WScript.CreateObject("WScript.Shell")

WScript.Echo "Working: " & objShell.RegRead(working_path) 
WScript.Echo "Not Working: " & objShell.RegRead(failing_path)

执行时,我将从7-zip注册表项获取路径,但Test项返回以下错误:

enter image description here

错误提示:注册表未打开以供读取。

这里是测试 key 存在的证明:

enter image description here

我做错了什么?我还尝试通过 oReg.GetStringValue 读取 key ,但这总是返回 null。

最佳答案

您的脚本似乎在 32 位兼容脚本主机中运行,但在 64 位操作系统中运行。 由于 32 位应用程序会自动重定向到 64 位操作系统中注册表的 WOW6432Node 区域,因此 RegRead 方法会尝试读取 32 位等效路径,例如

HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Test

相反

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test

因此,如果重定向路径不存在,您将按预期收到该错误。

您可能需要在 64 位兼容脚本主机中强制运行脚本,以消除这种隐式注册表重定向。

关于vbscript - VBS RegRead 不返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18118632/

相关文章:

powershell - 尝试将 powershell 脚本转换为 VBscript

windows - COM 如何通过后期绑定(bind)查找并运行 DLL?

vbscript - 重用 ADODB.Command 的正确方法

c# - C# 中的 VBScript 错误处理

powershell - 从 Windows Server 2008 上的脚本打开 url

C++ 将数组写入注册表中的二进制条目

go - 无法通过golang删除注册表项

delphi - 在 Windows 注册表中隐藏 key 的最佳位置?

java - 在 Java 中,为什么 WindowsPreferences 对大写字母使用斜杠?

python - 在 VBS 中使用 WshShell.Run 运行 Python 脚本不会生成输出文件