I've got the following code which finds and prints out the values of of DWORD type within the key at SpecialUserRegDir
. Secondary part of this code is a number that simply increases with each iteration. Unfortunately, I can't find a way to access the variables, that seem to be getting calculated correctly.
@echo OFF
@setlocal EnableExtensions EnableDelayedExpansion
set SpecialUserRegDir=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
set number=0
set /a number+=1
REG QUERY "%SpecialUserRegDir%" /s | for /F %%f in ('findstr "REG_DWORD"') do @(
set /a number+=1 :: Output: Values I need (2,3 etc)
@Echo !number! :: Output: !number!
@Echo %number% :: Output: 1
@echo %%f :: Output: [name of registry value]
)
@Echo !number! :: Output: 1
@Echo %number% :: Output: 1
The registry part is not so important, because it works. I am wondering if there's a way to keep the loop structure and access the values of number
from within the loop.
EDIT: Only 1 of the outputs changed with new code:
for /F %%f in ('REG QUERY "%SpecialUserRegDir%" /s ^| findstr "REG_DWORD"') do (
set /a number+=1 :: Output: Values I need (2,3 etc)
@Echo !number! :: Output: !number!
@Echo %number% :: Output: 1
@echo %%f :: Output: [name of registry value]
)
@Echo !number! :: Output: 4 (correct, because there are 3 values)
@Echo %number% :: Output: 1 (expected....)
EDIT 2: Ignore the first edit. I had multiple notepads with code opened and saved the new code on older version without EnableDelayedExpansion
.