Jump to content

Regedit Query - Batch script to Au3


Go to solution Solved by Subz,

Recommended Posts

Hi, I'm new to AutoIT, and I need help running a .batch command in AutoIT using Reg Query

:: code
for /f "tokens=*" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\" /s /f "KeyFind"') do reg add "%%i" /v "RegValue" /t REG_DWORD / d"0" /f

What this command does is search the registry keys for the "KeyFind" key, however it is present in various keys, for example: "HKLM\SYSTEM\CurrentControlSet\Windows\ETC\KeyFind", "HKLM\SYSTEM\CurrentControlSet\Windows\Microsoft\KeyFind", "HKLM\SYSTEM\CurrentControlSet\Windows\ETC\Control\KeyFind".

Im try with RegEnumKey, however it only reads the keys of the requested key and not the derived ones

Thank you

Link to comment
Share on other sites

Welcome, it would be better for you to post your code so that we can diagnose, off the top I assume you're not incrementing the instance, here is a basic example of enumerating through keys:

Local $sRootKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Local $sRegValue = "DisplayName"
Local $iKey = 1
Local $sSubKey
While 1
    $sSubKey = RegEnumKey($sRootKey, $iKey)
    If @error Then ExitLoop
    $sResult = RegRead($sRootKey & $sSubKey, $sRegValue)
    If Not @error Then MsgBox(4096, $sRegValue, "Reg Key := " & $sRootKey & $sSubKey & @CRLF & "Reg Val := KeyFind" & @CRLF & "Result := " & $sResult, 1)
    $iKey += 1
WEnd

 

Link to comment
Share on other sites

1 hour ago, Subz said:

 

1 hour ago, Subz said:

Welcome, it would be better for you to post your code so that we can diagnose, off the top I assume you're not incrementing the instance, here is a basic example of enumerating through keys:

Local $sRootKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Local $sRegValue = "DisplayName"
Local $iKey = 1
Local $sSubKey
While 1
    $sSubKey = RegEnumKey($sRootKey, $iKey)
    If @error Then ExitLoop
    $sResult = RegRead($sRootKey & $sSubKey, $sRegValue)
    If Not @error Then MsgBox(4096, $sRegValue, "Reg Key := " & $sRootKey & $sSubKey & @CRLF & "Reg Val := KeyFind" & @CRLF & "Result := " & $sResult, 1)
    $iKey += 1
WEnd

 

 

The instance is incremented, but what I'm looking for is to get the derived keys "within" those same keys, and the keys I get are only those of the requested key.

I leave some images for better understanding and the batch command

Thank you

Batch command.png

Regedit Pic.png

Link to comment
Share on other sites

  • Solution

Does this following work for you?

Local $sRootKey = "HKLM\SYSTEM\CurrentControlSet\"
Local $sSearchKey = "StorPort"
Local $sRegValue = "EnableIdlePowerManagement"

_RegEnumSubKey($sRootKey)

Func _RegEnumSubKey($_sRootKey = $sRootKey)
    Local $iEnumRootkey = 1, $sSubKey
    While 1
        $sSubKey = RegEnumKey($_sRootKey, $iEnumRootkey) & "\"
            If @error Then ExitLoop
        $sSubValue = RegRead($_sRootKey & $sSubKey & $sSearchKey, $sRegValue)
        If Not @error Then ConsoleWrite("Reg Key   := " & $_sRootKey & $sSubKey & $sSearchKey & @CRLF & "Reg Value := " & $sRegValue & @CRLF & "Reg Data  := " & $sSubValue & @CRLF)
        _RegEnumSubKey($_sRootKey & $sSubKey)
        $iEnumRootkey += 1
    WEnd
EndFunc

 

Link to comment
Share on other sites

14 hours ago, Subz said:

Does this following work for you?

Local $sRootKey = "HKLM\SYSTEM\CurrentControlSet\"
Local $sSearchKey = "StorPort"
Local $sRegValue = "EnableIdlePowerManagement"

_RegEnumSubKey($sRootKey)

Func _RegEnumSubKey($_sRootKey = $sRootKey)
    Local $iEnumRootkey = 1, $sSubKey
    While 1
        $sSubKey = RegEnumKey($_sRootKey, $iEnumRootkey) & "\"
            If @error Then ExitLoop
        $sSubValue = RegRead($_sRootKey & $sSubKey & $sSearchKey, $sRegValue)
        If Not @error Then ConsoleWrite("Reg Key   := " & $_sRootKey & $sSubKey & $sSearchKey & @CRLF & "Reg Value := " & $sRegValue & @CRLF & "Reg Data  := " & $sSubValue & @CRLF)
        _RegEnumSubKey($_sRootKey & $sSubKey)
        $iEnumRootkey += 1
    WEnd
EndFunc

 

YES YES, its work, really thank you sooo much 😁👌

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...