2013-08-07 23 views
5

Voglio ottenere che tutti i valori di un percorso del Registro di sistema includano i valori delle relative sottocartelle. In questo momento ho letto i valori di una singola cartella da questo:Iterate attraverso le sottocartelle del Registro di sistema

const HKEY_LOCAL_MACHINE = &H80000002 
strComputer = "." 

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv") 

strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys 

For Each subkey In arrSubKeys 
    msgbox subkey ' Just for debugging 
Next 

Questa grande opera, ma in aggiunta ho bisogno di ottenere un elenco di sottocartelle della cartella. ci

regedit /e c:\testfile.reg 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 

è un modo per:

voglio ottenere un risultato (solo il contenuto è importante, non la formattazione e non c'è bisogno di scrivere in un file) come questo avrebbe comandato mi dà fai questo in vbs o devo usare il comando regedit da windows, con una chiamata a Wscript.Shell.

risposta

9

È necessario accedere alle sottochiavi. Prova questo:

Const HKEY_LOCAL_MACHINE = &H80000002 
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 

Sub EnumerateKeys(hive, key) 
    WScript.Echo key 
    reg.EnumKey hive, key, arrSubKeys 
    If Not IsNull(arrSubKeys) Then 
    For Each subkey In arrSubKeys 
     EnumerateKeys hive, key & "\" & subkey 
    Next 
    End If 
End Sub 

Set reg = GetObject("winmgmts://./root/default:StdRegProv") 

EnumerateKeys HKEY_LOCAL_MACHINE, strKeyPath 
+1

questo ha funzionato perfettamente, thx –

5

Inoltre ho trovato un davvero buon esempio sul web:

' Constants (taken from WinReg.h) 
' 
Const HKEY_CLASSES_ROOT = &H80000000 
Const HKEY_CURRENT_USER = &H80000001 
Const HKEY_LOCAL_MACHINE = &H80000002 
Const HKEY_USERS   = &H80000003 

Const REG_SZ  = 1 
Const REG_EXPAND_SZ = 2 
Const REG_BINARY = 3 
Const REG_DWORD  = 4 
Const REG_MULTI_SZ = 7 

' Chose computer name, registry tree and key path 
' 
strComputer = "." ' Use . for current machine 
hDefKey = HKEY_LOCAL_MACHINE 
strKeyPath = "SOFTWARE\Microsoft\Cryptography\Defaults\Provider" 

' Connect to registry provider on target machine with current user 
' 
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") 

' Enum the subkeys of the key path we've chosen 
' 
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys 

For Each strSubkey In arrSubKeys 

    ' Show the subkey 
    ' 
    wscript.echo strSubkey 

    ' Show its value names and types 
    ' 
    strSubKeyPath = strKeyPath & "\" & strSubkey 
    oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes 

    For i = LBound(arrValueNames) To UBound(arrValueNames) 
    strValueName = arrValueNames(i) 
    Select Case arrTypes(i) 

     ' Show a REG_SZ value 
     ' 
     Case REG_SZ   
     oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue 
     wscript.echo " " & strValueName & " (REG_SZ) = " & strValue 

     ' Show a REG_EXPAND_SZ value 
     ' 
     Case REG_EXPAND_SZ 
     oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue 
     wscript.echo " " & strValueName & " (REG_EXPAND_SZ) = " & strValue 

     ' Show a REG_BINARY value 
     '   
     Case REG_BINARY 
     oReg.GetBinaryValue hDefKey, strSubKeyPath, strValueName, arrBytes 
     strBytes = "" 
     For Each uByte in arrBytes 
      strBytes = strBytes & Hex(uByte) & " " 
     Next 
     wscript.echo " " & strValueName & " (REG_BINARY) = " & strBytes 

     ' Show a REG_DWORD value 
     ' 
     Case REG_DWORD 
     oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue 
     wscript.echo " " & strValueName & " (REG_DWORD) = " & CStr(uValue)    

     ' Show a REG_MULTI_SZ value 
     ' 
     Case REG_MULTI_SZ 
     oReg.GetMultiStringValue hDefKey, strSubKeyPath, strValueName, arrValues         
     wscript.echo " " & strValueName & " (REG_MULTI_SZ) =" 
     For Each strValue in arrValues 
      wscript.echo " " & strValue 
     Next 

    End Select 
    Next 

Next 
Problemi correlati