Reputation: 1646
I have got a simple code that prints out registry values in a specific key. The problem is, I'm getting active directory printed out with each iteration of the loop below.
For the record, I use a different key with only 2 DWORD values: NAME and Test
@Echo Off
set SpecialUserRegDir=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
REG QUERY "%SpecialUserRegDir%" /s | for /F %%f in ('findstr "REG_DWORD"') do (
@echo %%f
[increment will be here]
)
Output
C:\User\[username]\Desktop\RegTest>()
NAME
C:\User\[username]\Desktop\RegTest>()
Test
I know that this problem disappears if I replace the do block with a signle command, but there will be other code in do
block, so I can't replace it with singular command.
With that in mind, is there any way to write that REG QUERY command (and the combination after that) without printing out the C:\User\[username]\Desktop\RegTest>()
?
Upvotes: 4
Views: 55
Reputation: 57252
try with :
@Echo Off
set SpecialUserRegDir=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
REG QUERY "%SpecialUserRegDir%" /s | for /F %%f in ('findstr "REG_DWORD"') do @(
echo %%f
[increment will be here]
)
the pipe and the for turn echo on so you need to echo off the brackets too.
Upvotes: 3