I'm looking for a quick and easy way (I don't need any error checking) to switch between two reg files by opening a batch file.
If a user runs a batch file, the batch file should merge reg file A to the registry. If the user runs it again, the batch file should merge reg file B to the registry. If the user runs it again, file A is merged... you get the point.
In general, I think there are two ways to do this:
Currently, I'm doing this:
REG QUERY "KeyName" /v "ValueName" | Find "x"
IF ERRORLEVEL 1 regedit /S file1.reg
IF ERRORLEVEL 0 regedit /S file2.reg
The REG QUERY part seems to work, but at the IF ERRORLEVEL
statements something is going wrong. But maybe I should use a different method altogether.
Hoping for some suggestions.. Thanks in advance!
EDIT
Sorry for being a bit vague: I believe the previous solution didn't work, because when the first IF
is correct, the second IF
will be too after the first IF
's command. So I will need an IF ELSE
statement to prevent running the second IF
.
I've now come up with this solution, which works:
REG QUERY "KeyName" /v "ValueName" | Find "x
IF ERRORLEVEL 1 (REGEDIT /S "file1.reg") ELSE REGEDIT /S "file2.reg"
I was also wondering: would it be an improvement to have the registry key/values added inside the batch file instead of using seperate .reg files? The value types are REG_BINARY and REG_DWORD.
I would try this:
REG QUERY "KeyName" /v "ValueName" | Find "x"
IF ERRORLEVEL 1 (
regedit /S file1.reg
goto :EOF
)
regedit /S file2.reg
The IF condition is set to TRUE when the ERRORLEVEL is equal to, or greater than, the ERRORLEVEL number (see here: http://support.microsoft.com/kb/39585/en-us) so the second IF condition is always evaluated as true.