views:

62

answers:

2

I am trying to set variable to a registry path. And then querying a registry and trying to match with the variable.If both are same then goto execute. But for some reason Im getting error and looks like there is some problem with this command

set var=HKEY_LOCAL_MACHINE\System\x

IF reg query==var
GOTO EXecute
+1  A: 

What you're doing there is just comparing strings. How should the command interpreter know that reg query is a command (besides the fact, that it alone won't yield much useful stuff anyway).

What you need to do here is execute your program, capture its output and then compare. You can do this with the for /f command:

for /f %%x in ('reg query ...') do ...

However, the output of reg is human-readable, not machine-readable, so you need some work to get it right. Basically you need to ignore empty lines in that for statement and the header line as well ... and then you need to find the actual value that's of interest to you. This will get ugly pretty fast.

Joey
A: 
for /f %%a in ('reg query ...') do if "%var%" == "%%a" goto Execute
brianary
It is giving error %%a is unexpected at this time
alice7
The doubled % is for use within a batch file, they shouldn't be doubled if entered directly on a command line.
brianary