问题
There is some way to reproduce/Inject some MSI install error?
I would like my install will fail with some error 1xxx/2xxx.. (msi error codes) it doesn't matter which error code, What important that in the MSI logs I will see "Retun value 3".
* I am using WIX
回答1:
Not 100% sure what you need. Are you testing Windows Installer rollback and wanting to trigger it from your custom action? Or maybe you just want to write something into your MSI log file without triggering rollback? I suppose you might want both, but it sort of sounds like you may just want to write to the log.
Triggering Rollback
You can basically just trigger rollback in your MSI by returning an error code from your custom action and set the custom action to "check exit code". See below for a note on deferred versus immediate mode custom actions.
Also: only check exit code when you need to and can handle it, or else your setup could fail unexpectedly - often for some insignificant and obscure error (which then may break your major upgrade - or worse - for example your uninstall entirely. There are several unexpected scenarios. Always test all installation modes including upgrades).
There is also a feature in the WiX util extension that allows you to trigger a deferred failure: WixFailWhenDeferred. I have never tried it to be honest. List of standardized WiX custom actions (and see link to "Using Standard Custom Actions" in there). See Bob Arnson's blog on this.
Writing To Log File
Here is a link, for starters, on how to actually write into the log file itself: Writing to the Log File from a Custom Action. This is from Flexera (makers of Installshield), but it covers logging from different types of custom actions in general as well as their proprietary ways. I don't know what type of action you use. It is written by Robert Dickau (former Installshield / Flexera Senior Technical Trainer) and features his great ability to keep things as simple as possible despite the advanced topic. It is a quick read.
There may be better ways to do this from managed code that I haven't used. Let's wait and see if Chris Painter comes back with some info here (WiX/MSI expert - on managed code in particular).
It has been ages, but I think I actually ended up logging into the event log instead of the log file back in the day when I was working on things like this. It was for corporate use, and the event log was used extensively. It is all a blur now I am afraid, and I don't have sample code for this available.
Digression: Immediate Mode vs Deferred Mode
Digression: Note that no rollback will happen in immediate mode (for example when you are clicking through the setup's user interface). In immediate mode there is no change transaction to roll back, you just end execution basically. No changes should ever be made to the system using immediate mode custom actions for this reason - they can't be rolled back (and they don't run elevated either - though they can run with real admin rights and hence make changes seemingly successfully, but this is always wrong design and will cause you grief). This is very important, hence this mention.
For what it is worth: it beats me why immediate mode custom actions don't just crash if attempting to write anywhere. Crash bugs can't be ignored, and we would have been better off? Maybe I am missing something.
回答2:
I have used a VBScript deferred custom action that divides by zero. Condition the call on a property passed in on the msiexec command line. That'll cause a rollback and return error 3.
来源:https://stackoverflow.com/questions/48137866/how-to-reproduce-msi-install-error