我有一个脚本检索特定键(例如:HKEY_LOCAL_MACHINESOFTWAREMicrosoftASP.NET
)中的所有注册表值,但我需要在使该搜索递归时进行咨询。我需要打印此键以下的所有注册表和子键(例如:HKEY_LOCAL_MACHINESOFTWAREMicrosoftASP.NET
)
脚本示例:
For Each strSubkey In arrSubKeys
Set objHtml=fso.Opentextfile(strComputer & ".txt",intForWriting,Createfile)
strValue = Null
strSubKeyPath = pathKeyReg & "" & strSubkey
objRegistry.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes
For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)
Case REG_SZ
objRegistry.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
objHtml.WriteLine strSubKeyPath & vbTab & strValueName & vbTab & "(REG_SZ)" & vbTab & strValue
' Show a REG_EXPAND_SZ value
Case REG_EXPAND_SZ
objRegistry.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
objHtml.Write strSubKeyPath & vbTab & strValueName & vbTab & "(REG_EXPAND_SZ)" & vbTab & strValue
End Select
Next
Next
需要递归到子键中。将代码封装在过程中,并添加枚举当前键的子键并为每个子键调用自身的代码。
Sub RecurseKey(key)
'enumerate values (your existing code)
objRegistry.EnumValues hDefKey, key, names, types
If Not IsNull(names) Then
For i = 0 To UBound(names)
name = names(i)
Select Case types(i)
Case REG_SZ
...
Case REG_EXPAND_SZ
...
Case ...
End Select
Next
End If
'enumerate subkeys and recurse
objRegistry.EnumKey hDefKey, key, subKeys
If Not IsNull(subKeys) Then
For Each sk In subKeys
RecurseKey key & "" & sk '<-- recursion happens here
Next
End If
End Sub