vbs使用wmi遍历注册表路径子目录和目录数据
wmi如何遍历指定注册表路径下的子目录,以及注册表路径右边的名称键值对集合。

' 定义常数 (来源 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
strComputer = "." '计算机名,使用.选择当前计算机
hDefKey = HKEY_LOCAL_MACHINE
strKeyPath = "SOFTWARE\Microsoft\Cryptography\Defaults\Provider"'要遍历的注册表路径
' 使用当前用户连接目标机器注册表wmi
'
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' 获取注册表路径包含的子键
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
For Each strSubkey In arrSubKeys
'输出子键
'
wscript.echo strSubkey
' 获取子键包含的键值对和类型
'
strSubKeyPath = strKeyPath & "\" & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes
For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)'注意判断值类型,不同类型需要使用不同的方法
Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_SZ) = " & strValue
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_EXPAND_SZ) = " & strValue
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
Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
wscript.echo " " & strValueName & " (REG_DWORD) = " & CStr(uValue)
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
来源:http://stackoverflow.com/questions/18098319/iterate-through-registry-subfolders
加支付宝好友偷能量挖...

