/build/static/layout/Breadcrumb_cap_w.png

Reporting on ERRORLEVEL in Batch Scripts?

I am working on creating a standard wrapper of sorts around my post-installation scripts, with an introduction, execution of installation package, error-catching, and notification of script end.

My method of detecting any error has been as such:

@ECHO OFF
echo ******************
echo Installing Aleks...
msiexec /i %~dp0aleks318.msi /qb
IF %ERRORLEVEL% EQU 0 GOTO success
GOTO error
:success
echo Aleks Installed.
echo ******************
GOTO END
:error
echo An error %ERRORLEVEL% occured. >> %systemroot%\Aleks_Error.log
GOTO END
:end
However, this particular software seems to exit setting ERRORLEVEL to 1 no matter what, although the software seems to be installed just fine.

So I am wondering if I should expect software installation packages to not always leave ERRORLEVEL as 0, even when the software installed without error.

Has anybody else set up a similar sort of mechanism? Is there any better ways to check for errors? 

 


0 Comments   [ + ] Show comments

Answers (3)

Posted by: SMal.tmcc 11 years ago
Red Belt
1

have you tried to set the errorlevel to 0 just before running the MSI? some internal system commands could also do this prior to the msi call.

http://www.incodesystems.com/products/errorle1.htm

Posted by: ontari.ontari 11 years ago
Black Belt
1

I am not sure about client side error message!! but if you need exit codes for deployment troubleshoot you can use this bach command 

@ECHO OFF
echo ******************
echo Installing Aleks...
msiexec /i %~dp0aleks318.msi /qb

REM Return exit code to SCCM
exit /B %EXIT_CODE%

Posted by: M P 11 years ago
Purple Belt
0

Try using "START /WAIT" in front of your line for the install using "MSIEXEC" and see if it provides the correct results.  This should make the script wait for the installation to finish and read the correct value of the ErrorLevel.  Also, be sure that the path to the MSI does not contains spaces or special characters that would require the path to be enclosed in quotes.  If you pass an invalid path (or GUID) to MSIEXEC it will not update the ErrorLevel.

 

@ECHO OFF
echo ******************
echo Installing Aleks...
START /WAIT msiexec /i %~dp0aleks318.msi /qb
IF %ERRORLEVEL% EQU 0 GOTO success
GOTO error
:success
echo Aleks Installed.
echo ******************
GOTO END
:error
echo An error %ERRORLEVEL% occured. >> %systemroot%\Aleks_Error.log
GOTO END
:end

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ