0
votes

I have an installer written in WIX, that has a WPF Bootstrapper. Recently we added a silent installation mode, and we need to use return codes in order to specify what kind of error occurred during silent installation, for instance: invalid username or password, incorrect server address, unsupported Windows version, etc.

We use the Engine.Quit() method from Bootstrapper class to exit the installer with an exit code. This exit code can be seen in the installer log:

[5490:4F84][2018-09-14T14:31:03]i007: Exit code: 0x101, restarting: No

However, when I check the %errorlevel% environment variable, it remains unchanged. Using Environment.Exit() did not help either.

I suspected, that MSI might be responsible for such behavior by overwriting what WIX tried to set, but even forcing ActionResult.Failure in one of the actions of installer does not help. The MSI exit code is in the MSI log, but %errorlevel% remains unchanged:

MSI (c) (AC:9C) [14:30:59:133]: MainEngineThread is returning 1603
=== Verbose logging stopped: 2018-09-14  14:30:59 ===

Is it possibe to make WIX set the %errorlevel% to a custom value, and if yes, how can it be done?

1
Are you using a batch file? Can we see it? Or are you doing something per-MSI or per-EXE inside the WiX bundle?Stein Åsmul

1 Answers

1
votes

The %ERROPRLEVEL% value is a feature that you get in batch file environments (the Windows cmd BAT shell, and also PowerShell, I believe) so you're not going to see that value outside of a scripting batch environment. It's not clear from your post if your silent install is a batch script or not.

Having said that, an MSI install process returns standard Windows error results that are documented here:

https://docs.microsoft.com/en-us/windows/desktop/Msi/error-codes

so they can't be customized. The particular errors you mentioned (such as invalid user name or invalid server address) appear to be errors from your custom action code in the MSI. People generally deal with error diagnostics in custom actions by using the logging features of Windows Installer to add your messages to the standard log file. This uses MsiProcessMessage() or equivalent as here:

https://social.msdn.microsoft.com/Forums/windows/en-US/5698aaee-11e5-4a8c-b307-f96b9eb1884f/writing-custom-messages-to-log-file-of-msi-using-msiprocessmessage?forum=winformssetup

https://docs.microsoft.com/en-us/windows/desktop/msi/sending-messages-to-windows-installer-using-msiprocessmessage

So you're not going to get errors specific to your custom actions unless you arrange to record the details in the log, as above, or put them somewhere that your silent install can see them (registry?).