set variable?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
5OEMC
Posts: 2
Joined: 08 Apr 2017 14:38

set variable?

#1 Post by 5OEMC » 08 Apr 2017 15:11

mykey.reg

Code: Select all

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\MyKey\1]
[-HKEY_CURRENT_USER\MyKey\2]
[-HKEY_CURRENT_USER\MyKey\3]
[-HKEY_CURRENT_USER\MyKey\4]
[-HKEY_CURRENT_USER\MyKey\5]

Code: Select all

for /f "tokens=1 delims=[-]" %%G in (mykey.reg) do reg query %%G /ve 2> nul | find "HKEY"

Question: Is it possible to set the output as a variable to allow further processing registry key if it was found?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: set variable?

#2 Post by aGerman » 09 Apr 2017 08:36

Your list contains 5 keys. That means you may get 5 positives or even 0 if none were found. Your best bet is to execute the result in a second FOR /F loop in order to work with the FOR Variable directly.

Steffen

5OEMC
Posts: 2
Joined: 08 Apr 2017 14:38

Re: set variable?

#3 Post by 5OEMC » 09 Apr 2017 11:22

Yep, thanks. Now I see that my attempt using variable outside loop was just very dumb thing :oops:

Post Reply