The "problem" with your code is that when the parser reach that line, the %errorlevel% variable is replaced with its value, and then the line is executed. So, any change to the value of the variable is not seen. The "usual" way of handling this cases is enabling delayed expansion and change the %errorlevel% sintax with !errorlevel! to indicate the parser that the value will change and need to be retrieved at execution time.
But, in this case, as you have the requirement of a "one liner", change the if test to
if errorlevel 1 (echo "SQL Not Installed") else (echo "SQL Installed")A standard construct to check for errorlevel without reading the variable value.
You have also the posibility to code it as
reg query .... && echo Installed || echo Not InstalledThis executes the reg command (with all your parameters, of course). On success, the command after && is executed. On failure the command after || is executed.
ليست هناك تعليقات:
إرسال تعليق