0

I need to read a data from registry, add 1 to it and then rewrite the data back in registry

FOR /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Looptest" /v "subcounter"') do set "subcounter=%%b"

if %subcounter% EQU 6 (
    set /a counter=%counter%+1
    echo increasing value for counter %counter% >> abc.log
    reg add HKLM\Software\Looptest /f /v counter /t REG_SZ /d %counter%
    pause
)

But,the problem in this code is that, it does not increase the data of COUNTER. Any explanation ?

Thanks !

Srijani Ghosh
  • 3,935
  • 7
  • 37
  • 68

1 Answers1

2

Specifically...

@echo off & setlocal enabledelayedexpansion
FOR /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Looptest" /v "subcounter"') do set "counter=%%b"

if %counter% EQU 6 (
    set /a counter+=1
    echo increasing value for counter !counter! >> abc.log
    reg add HKLM\Software\Looptest /f /v counter /t REG_SZ /d !counter!
)

Alternatively, use CALL, and double %%.

@echo off
FOR /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Looptest" /v "subcounter"') do set "counter=%%b"

if %counter% EQU 6 (
    set /a counter+=1
    call echo increasing value for counter %%counter%% >> abc.log
    call reg add HKLM\Software\Looptest /f /v counter /t REG_SZ /d %%counter%%
)
soja
  • 1,587
  • 8
  • 8