Need help in finding the root cause in this wrong batch command
IF %processor_architecture% == AMD64 (SET querypath=hkl开发者_如何学Gom\software\x) ELSE (SET dsetquerypath=hklm\software\y)
FOR /F "tokens=* delims=\" %%G IN ('REG QUERY "%querypath%" 2^>NUL') DO ECHO %%G
Let me explain what im trying to accomplish out of this batch command. Basically there is a tool which gets intalled on hklm\software\x(on 32bit windows) and hklm\software\y(on 64 bit windows).
I need the exact path of the software from registry.Which could tell me whether the machine is 32 or 64 bit and take appropriate action. But right now every time I using this batch command it is always returning path as hklm\software\y.
I don't know WHY? That is what I need help to make this batch file right.
EDIT: I think this may provide an explanation and solution to your problem, and in batch too :)
The spaces around the ==
may be causing your problem.
You're actually comparing the value of %processor_architecture%[space]
to [space]AMD64
Try:
IF %processor_architecture%==AMD64...
If Command Extensions are enabled you can also do:
IF /I %processor_architecture% equ AMD64
(the /I
switch makes the IF case insensitive)
It works as expected if AMD64 is quoted:
set processor_architecture="AMD64" IF %processor_architecture% == "AMD64" (SET querypath=hklm\software\x) ELSE > (SET querypath=hklm\software\y) echo querypath=%querypath%
What about this:
ECHO processor_architecture="%processor_architecture%"
SET querypath=hklm\software\y
IF "%processor_architecture%" == "AMD64" SET querypath=hklm\software\x
Also note you have some typos on your ELSE
part; isn't the problem there?
I think you are falling victim to the phenomenon where the variables are expanded/evaluated as soon as they are read. There is a good discussion of that at Raymond Chen's blog.
Also search on "immediate expansion" and "delayed expansion".
精彩评论