2017-03-03 89 views
0

我使用這行代碼來填充包含sPath結尾處的註冊表項的數組。它適用於除Win7以外的任何實例。適用於Win8,Win10沒有問題。我已經驗證了鑰匙存在,所以不是這樣。在不使用oReg.EnumKey的情況下在VBS中創建註冊表鍵陣列

ret = oReg.EnumKey(&H80000002, sPath, guidlist) 

我試圖讀出「ret」的返回值,但它看起來是空白的或可能是NULL?我使用'objLog.WriteLine'這是ret「& ret'。但它只寫出「這是ret」

是否有另一種方法來創建使用VBS的數組?

+0

您的程序是否以管理員身份運行?它可能沒有它需要的權限。 –

+0

它以管理員身份運行。我想我知道發生了什麼事。在Win7上,EnumKey默認爲WOW6432註冊表。我正在尋找的關鍵是在64位註冊表樹中。我將搜索如何指定要使用的註冊表的哪一部分。 –

回答

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 
1

EnumKey是正確的做法。 guidlist將包含您想要的輸出,而不是ret

+0

我只查看「ret」的情況下,它未能嘗試並找出原因。 –

相關問題