在路径的所有子项中搜索注册表项

时间:2011-11-30 08:02:16

标签: vbscript registry

我想在HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE下找到关键字“设备参数”。

但是,BD/DVD/CD ROM/Writers在每个系统中都有不同的键。我的目前是HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\CdRomHL-DT-ST_DVDRAM_GH20NS15________________IL00____\5&15602d3e&0&0.1.0\Device Parameters

但我想在IDE下和BD/DVD/CD ROM/Writers下搜索每个子项以获取设备参数。有一个二进制值DefaultDVDregion,我想为每个BD/DVD/CD ROM/Writers将其设置为0。

我想在VBScript中这样做。

1 个答案:

答案 0 :(得分:5)

此代码将遍历HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE中的所有键,并且对于每个键,在其中查看以打印出DefaultDvdRegion的DWORD值。

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

这不是我最好的代码,但应该给你你想要的东西。在我的机器上,我得到以下输出:

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 =

这是有道理的,因为我的DVD驱动器的区域代码为2(欧洲),而我的硬盘驱动器没有区域代码。