我想实现的目标我觉得应该相当简单,但它让我完全发疯。
背景: 我们在我们的客户端运行一个系统监控工具,它能够远程运行 .vbs 脚本。这通常工作得很好。
我目前正在努力实现的是能够在 32 位版本的 Windows 和 64 位版本的 Windows 上从注册表中读取一行。
监控机器的 Client side.exe 在两个平台上都作为 32 位进程运行(这就是诀窍)。
例如,我想从 HKEY_LOCAL_MACHINE\SOFTWARE\读取一个 key 。我的脚本在 32 位上运行良好。示例:objRegistry.RegRead("HKEY_LOCAL_MACHINE\Software\anything")
我遇到的问题是,当我在 64 位文件夹上运行同一行时,会自动在 wow64node 文件夹中查找。示例:objRegistry.RegRead("HKEY_LOCAL_MACHINE\Software\wow64node\")。
我需要让它在完全相同的地方检查。
它正在读取的 key 是同时运行 32 位和 64 位版本的程序的一部分,这就是为什么它没有安装在 wow64node 文件夹中的原因。
此时我无法将 .VBS 脚本作为 64 位进程运行,这将完全解决我的问题,因为它不会在 wow64node 文件夹中查找。
如果有人有任何想法,请告诉我。
最佳答案
我用这段代码解决了它。
Const HKEY_LOCAL_MACHINE = &H80000002
sPath = ReadRegStr (HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\ASP.NET\2.0.50727.0", "Path", 64)
WScript.Echo sPath
' Reads a REG_SZ value from the local computer's registry using WMI.
' Parameters:
' RootKey - The registry hive (see http://msdn.microsoft.com/en-us/library/aa390788(VS.85).aspx for a list of possible values).
' Key - The key that contains the desired value.
' Value - The value that you want to get.
' RegType - The registry bitness: 32 or 64.
'
Function ReadRegStr (RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams
Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType
Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")
Set oInParams = oReg.Methods_("GetStringValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value
Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)
ReadRegStr = oOutParams.sValue
End Function
谢谢海伦的帮助!
关于windows - VBS Windows 64bit/32bit 注册表读取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6991431/