我使用这行代码在sPath末尾用注册表项填充数组。它适用于除Win7之外的所有实例。适用于Win8,Win10没问题。我已经验证了密钥存在,所以不是那样。
ret = oReg.EnumKey( &H80000002, sPath, guidlist)
我试图读出“ret”的返回值,但它看起来是空白还是NULL?我使用'objLog.WriteLine'这是ret& RET”。但它只写出“This is ret”
是否有另一种使用VBS创建阵列的方法?
答案 0 :(得分:1)
EnumKey是正确的方法。 guidlist
将包含您想要的输出,而不是ret
。
答案 1 :(得分:0)
这是我在不使用EnumKey的情况下从32位应用程序访问64位注册表时必须使用的代码。
objLog.WriteLine "Begin StdRegProv reg read method"
strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")
objLog.WriteLine "About to call EnumKey with ExecMethod"
' Use ExecMethod to call the EnumKey method
Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = sPath
'InParams.aArrayOfGuids = guidlist()
'Inparams.Svaluename = "Logging"
set Outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams,,objCtx)
objLog.WriteLine "Finished creating array of guids"
'read values in array
'For Each guid In Outparams.snames
' objLog.WriteLine "these are the guids in the array - " & guid
'Next
For each guid1 in Outparams.snames
dim InstallPropertiesPath
InstallPropertiesPath = sPath & "\" & guid1 & SubPath1
objLog.WriteLine "The InstallPropertiesPath is " & InstallPropertiesPath
' Use ExecMethod to call the GetStringValue method
Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = InstallPropertiesPath
Inparams.sValueName = "LocalPackage"
'InParams.aArrayOfGuids = guidlist()
'Inparams.Svaluename = "Logging"
set Outparams = Nothing
set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)
objLog.WriteLine "About to call DetectMSIFeature with this path - " & Outparams.SValue