vbscript - 遍历注册表子文件夹

标签 vbscript registry subdirectory regedit

我想获取注册表路径的所有值,包括其子文件夹的值。现在我通过以下方式读取单个文件夹的值:

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

这很好用,但此外我需要获取文件夹子文件夹的列表。

我想要得到一个结果(只有内容很重要,格式并不重要,也不需要将其写入文件),就像这个命令给我的结果一样:

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

有没有办法在 vbs 中执行此操作,或者我需要通过 Wscript.Shell 调用使用 Windows 中的 regedit 命令。

最佳答案

您需要递归到子项。试试这个:

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

关于vbscript - 遍历注册表子文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18098319/

相关文章:

vbscript - 如何使用VB脚本检查进程是否正在运行?

c++ - 如何在Windows中模拟注册表进行程序测试?

c# - 文件类型图标未在 Visual Studio 中更新

powershell - 如何在正确访问 Windows 注册表的情况下在 WiX 中启动 PowerShell?

python - 如何纯粹用Python获取目录的子目录名称?

internet-explorer - 重用 Internet Explorer COM 自动化对象

vbscript - 如何从字符串中删除前导零

linux - 查找每个目录的最大文件

c# - 如何确定目录/文件夹是否已更改

excel - 带有 VBScript 的表格样式