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 !

3

1 Answer 1

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%%
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.