Reputation: 21
I'm trying to get my batch script to check if two registry keys exist and if they do, goto...
So far, my code works but just need it to check if both keys exist as well as if one or the other exists as there may be cases when HKCU\SOFTWARE\MICROSOFT\OFFICE\14.0
and HKCU\SOFTWARE\MICROSOFT\OFFICE\15.0
both exist.
I need it to execute :O2010
and :O2013
if both keys exist.
At the moment, if both exist then it just stops after it runs :O2010
@ECHO OFF
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\14.0 > NUL
IF NOT ERRORLEVEL 1 GOTO :O2010
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\15.0 > NUL
IF NOT ERRORLEVEL 1 GOTO :O2013
GOTO :END
:O2010
reg import \\path_to_reg_file\regkey1.reg
GOTO :END
:O2013
reg import \\path_to_reg_file\regkey2.reg
GOTO :END
:END
Any help would be much appreciated.
Upvotes: 2
Views: 5866
Reputation: 41224
This will import the reg keys as below:
A) if either key exists it will import the associated reg key
B) if both keys exist it will import both keys
@ECHO OFF
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\14.0 > NUL && reg import \\path_to_reg_file\regkey1.reg
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\15.0 > NUL && reg import \\path_to_reg_file\regkey2.reg
Upvotes: 0
Reputation: 7095
Something like this should do it:
@ECHO OFF
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\12.0 > NUL
IF NOT ERRORLEVEL 1 set f1=1
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\15.0 > NUL
IF NOT ERRORLEVEL 1 set f2=2
set /a f3=f1+f2
if %f3%==1 (echo reg import \\path_to_reg_file\regkey1.reg)
if %f3%==2 (echo reg import \\path_to_reg_file\regkey2.reg)
if %f3%==3 (echo reg import \\path_to_reg_file\regkey1.reg & echo reg import \\path_to_reg_file\regkey2.reg)
Upvotes: 0
Reputation: 42870
Do you mean like this?:
@ECHO OFF
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\14.0 > NUL
IF NOT ERRORLEVEL 1 reg import \\path_to_reg_file\regkey1.reg
REG QUERY HKCU\SOFTWARE\MICROSOFT\OFFICE\15.0 > NUL
IF NOT ERRORLEVEL 1 reg import \\path_to_reg_file\regkey2.reg
Upvotes: 1