レジストリの値を取得するスクリプト

書込みがあれば読込めとかいう無茶振りもある・・・。 仕方がないので色々と探しました。 まんまパクリですが・・・・・。 とりあえず可変値でも何とか取得できるし、これで値は取れそうです。 後はCSVに吐き出させてそれをEXCELに取込ませるという面倒なことを しないといけない。やめてくれよなぁこういうの
'refer
'https://gallery.technet.microsoft.com/scriptcenter/d9d76585-4338-400e-a7a5-48ad6664f496
'https://stackoverflow.com/questions/18098319/iterate-through-registry-subfolders
'http://www.tek-tips.com/viewthread.cfm?qid=1162228


Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

'読取りたいキーのパス指定
strOriginalKeyPath = "SOFTWARE\*****"

'関数呼出
FindKeyValue(strOriginalKeyPath)

'-------------------------------------------------------------------------
'   レジストリキーを再帰的に取得する。
'-------------------------------------------------------------------------
Function FindKeyValue(strKeyPath)
    
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
        strComputer & "\root\default:StdRegProv")

    errorCheck = oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)
    
    If (errorCheck=0 and IsArray(arrSubKeys)) then
        For Each subkey In arrSubKeys
            '
            Wscript.Echo subkey
            '
            strNewKeyPath = strKeyPath & "\" & subkey
            FindKeyValue(strNewKeyPath)
        Next
    End If

    oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, _
           arrValueNames, arrValueTypes
 
    If (errorCheck=0 and IsArray(arrValueNames)) then
        For i=0 To UBound(arrValueNames)
  '        Wscript.Echo "Value Name: " & arrValueNames(i)
          'キー名を取得する。
          strValueName = arrValueNames(i)
          '再帰的に取得した値を表示する
          Select Case arrValueTypes(i)
                  Case REG_SZ
                      oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
                      '
                      wscript.echo arrValueNames(i) & "Value: " & strvalue
                      '
                  Case REG_EXPAND_SZ
                      oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strEXValue
                      '
                      wscript.echo arrValueNames(i) & "Value: " & strExvalue
                      '
                  Case REG_BINARY
                      oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrBytes
                      strBytes = ""
                      For Each uByte in arrBytes
                        strBytes = strBytes & Hex(uByte) & " "
                      Next
                      '
                      wscript.echo arrValueNames(i) & ":" & strBytes
                      '
                  Case REG_DWORD
                      oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
                      '
                      wscript.echo arrValueNames(i) & ": " & Cstr(dwvalue)
                      '
                  Case REG_MULTI_SZ
                      oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrValues
                      strText = arrValueNames(i) & ": "
                      For Each strValue in arrValues
                          strText = strText & "    " & strValue 
                      Next
                      '
                      wscript.echo strText 
                      '
          End Select 
        Next
    End if
end Function

コメント

このブログの人気の投稿

証券外務員1種勉強(計算式暗記用メモ)

GASでGoogleDriveのサブフォルダとファイル一覧を出力する

マクロ経済学(IS-LM分析)