遍历注册表子文件夹 [英] Iterate through Registry Subfolders
问题描述
我想获取注册表路径的所有值,包括其子文件夹的值.现在我通过这个读取单个文件夹的值:
I want to get all values of a registry path include the values of its subfolders. Right now i read the values of a single folder by this:
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
这很好用,但除此之外,我还需要获取文件夹的子文件夹列表.
This works great, but in addition i need to get a list of the folder's subfolders.
我想得到一个结果(只有内容很重要,格式不重要,不需要将其写入文件)就像 this will 命令给我的:
I want to get a result (only the content is important, not the formatting and no need to write it into a file) like the this would command gives me:
regedit /e c:\testfile.reg
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
有没有办法在 vbs 中做到这一点,或者我是否需要使用 Windows 中的 regedit 命令,并通过 Wscript.Shell 调用.
Is there a way to do this in vbs or do i need to use the regedit command from windows, with an Wscript.Shell call.
推荐答案
您需要递归到子项中.试试这个:
You need to recurse into the subkeys. Try this:
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
这篇关于遍历注册表子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!