「レジストリ キーのすべての値を取得する方法はありますか」 のサイトを参考にwmiの勉強
VBSのソースコードをVBA用に焼直したもの
microsoft wmi scripting 1.2 参照設定させることが前提
余裕がでたら、もう少し解析してみたい。
Sub レジストリキーのすべての値を列挙()
‘https://gallery.technet.microsoft.com/scriptcenter/d9d76585-4338-400e-a7a5-48ad6664f496
Const HKEY_CURRENT_USER As Long = &H80000001
Const REG_SZ As Integer = 1
Const REG_EXPAND_SZ As Integer = 2
Const REG_BINARY As Integer = 3
Const REG_DWORD As Integer = 4
Const REG_MULTI_SZ As Integer = 7
Const HKEY_CLASSES_ROOT = &H80000000 ‘ROOT固定
Const REG_KEY As String = "TypeLib" ‘TypeLib固定
Dim strComputer As String: strComputer = "."‘microsoft wmi scripting 1.2 参照設定させる。
Dim oDiskSet As SWbemObjectSet
Dim objRegistry As SWbemObjectEx
Dim oLocator As SWbemLocator
Dim oService As SWbemServices
Set oLocator = New WbemScripting.SWbemLocator
Set oService = oLocator.ConnectServer
Set objRegistry = oService.Get("StdRegProv")
‘Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Dim strKeyPath As String: strKeyPath = "Software\Microsoft\Internet Explorer\Main"
‘ Dim strKeyPath As String: strKeyPath = "Software"
objRegistry.EnumValues HKEY_CURRENT_USER, strKeyPath, arrValueNames, arrValueTypes
‘ Call GetKeys(objRegistry, REG_KEY, arrValueNames)
For i = 0 To UBound(arrValueNames)
strText = arrValueNames(i)
strValueName = arrValueNames(i)
Select Case arrValueTypes(i)
Case REG_SZ
objRegistry.GetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
strText = strText & ": " & strValue
Case REG_DWORD
objRegistry.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, intValue
strText = strText & ": " & intValue
Case REG_MULTI_SZ
objRegistry.GetMultiStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strValue In arrValues
strText = strText & " " & strValue
Next
Case REG_EXPAND_SZ
objRegistry.GetExpandedStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue
strText = strText & ": " & strValue
Case REG_BINARY
objRegistry.GetBinaryValue HKEY_CURRENT_USER, strKeyPath, strValueName, arrValues
strText = strText & ": "
For Each strValue In arrValues
strText = strText & " " & strValue
Next
End Select
Debug.Print strText
NextEnd Sub
コメント