Search for registry key in all of the subkeys of a path

19,140

This code will loop through all the keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE and, for each key, look inside it to print out the DWORD value of DefaultDvdRegion.

Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim oReg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim oShell : Set oShell = CreateObject("WScript.Shell")
Dim sPath, aSub, sKey, aSubToo, sKeyToo, dwValue

' Get all keys within sPath
sPath = "SYSTEM\CurrentControlSet\Enum\IDE"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aSub

' Loop through each key
For Each sKey In aSub
    ' Get all subkeys within the key 'sKey'
    oReg.EnumKey HKEY_LOCAL_MACHINE, sPath & "\" & sKey, aSubToo
    For Each sKeyToo In aSubToo
        ' Try and get the DWORD value in Device Parameters\DefaultDvdRegion
        oReg.GetDWORDValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey & "\" & sKeyToo & "\Device Parameters", "DefaultDvdRegion", dwValue
        Wscript.Echo "DVDRegion of " & sPath & "\" & sKey & "\" & sKeyToo & " = " & dwValue
    Next
Next

It's not my finest code, but should give you what you are looking for. On my machine, I get the following output:

DVDRegion of SYSTEM\CurrentControlSet\Enum\IDE\CdRomOptiarc_DVD_RW_AD-7200S_________________1.0A____\5&3308a5ad&0&1.0.0 = 2  
DVDRegion of SYSTEM\CurrentControlSet\Enum\IDE\DiskSAMSUNG_HD103UJ_________________________1AA01113\5&76d4b99&0&0.0.0 =

Which makes sense, because my DVD drive has a region code of 2 (Europe) and my hard drive has no region code.

Share:
19,140
user1070733
Author by

user1070733

Updated on June 05, 2022

Comments

  • user1070733
    user1070733 almost 2 years

    I want to find the key "Device Parameters' under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE.

    But, the BD/DVD/CD ROM/Writers makes a different key in every system. Mine currently is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\CdRomHL-DT-ST_DVDRAM_GH20NS15________________IL00____\5&15602d3e&0&0.1.0\Device Parameters.

    But I want to search every subkey under IDE and under BD/DVD/CD ROM/Writers to get the device parameters. There is a binary value DefaultDVDregion and i want to set it to 0 for every BD/DVD/CD ROM/Writers.

    I'd like to do this in VBScript.