我需要从注册表中读取数据,向其中添加1,然后在注册表中重写数据
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
)
但是,这段代码中的问题是,它不会增加COUNTER的数据。有什么解释吗?
谢谢!
答案 0 :(得分:2)
...具体
@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!
)
或者,使用CALL
,然后加倍%%
。
@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%%
)