2013-08-07 17 views
5

Bir kayıt defteri yolunun tüm değerlerini alt klasörlerinin değerlerini dahil etmek istiyorum. Şu anda ben bu tek bir klasörün değerlerini okuyun: Bu harika çalışıyorKayıt Defteri Alt Klasörleri aracılığıyla yineleme

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 

fakat ek olarak i klasörün alt klasörlerin listesini almak gerekir.

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

bir yolu var mı:

Bir sonuç almak isteyen bu komuta edeceği bana verir gibi (yalnızca içerik önemli değil, biçimlendirme ve bir dosyaya yazmak için gerek yoktur) Bunu vbs'de yapın veya bir Wscript.Shell çağrısı ile pencerelerden regedit komutunu kullanmam gerekir.

cevap

9

Alt anahtarlara tekrar girmeniz gerekir. Bu deneyin: Ayrıca

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

, thx –

5

i web üzerinde gerçekten iyi bir örnek bulundu: Bu çok iyi çalıştı

' 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 
İlgili konular