I have a bootstrapper application which installs several MSI packages. However, it seems that windows installer does not return any error code if the installation fails. For example, the following command line test does not print "failed" if I hit "cancel":
msiexec /i myinstaller.msi || echo failed
Given the lack of error feedback, what is the best way to detect an installation failure?
As the accepted answer suggests, an error code is actually returned. For some reason my test case only works as expected when executed from a batch file, rather than typed directly at a command line.
Source: https://blogs.msdn.microsoft.com/heaths/2005/11/15/waiting-for-msiexec-exe-to-finish/
Sample code:
Code reference: https://www.computing.net/answers/windows-xp/batch-file-to-install-msi-and-check-errorlvl/178657.html
If you hit cancel it isn't an error, the installer is performing the requested action, and is most likely returning 0 to the cancel function.
Actually,
msiexec
does return error codes, the two success codes being 0 (success) and 3010 (success, reboot required). Maybe cmd.exe does some unwanted magic in your example (like returning before msiexec has finished), but I successfully read msiexec error codes when executing it via VBScript's WScript.Shell Run (with bWaitOnReturn = True).Try throwing the following in a test.vbs file and then executing it with
cscript test.vbs
:It should pop up with a non-zero value if you hit Cancel.
msiexec does return an error on installation failure. To catch a user cancel, you might need to use a MIF file.