Search code examples
batch-fileregedit

How to verify regedit result?


How do I verify the value of a regedit query request?

REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" 
IF result == 1 goto turoff
IF result == 0 goto turnon

Solution

  • If you're just wanting to toggle the value betwen 1 and 0, something along these lines may work for you, (as long as you have the appropriate permissions to access/modify the value data).

    @Echo Off
    Set "DWord="
    For /F "Tokens=3" %%A In ('
        Reg Query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" 2^>Nul
    ') Do 2>Nul Set /A DWord=1-%%A
    If Defined DWord Reg Add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V "HiberbootEnabled" /T REG_DWORD /D %DWord% /F>Nul