简体   繁体   中英

How to retrieve detailed result from msi installation

I have a .msi file created by Wix toolset, used to install 5 drivers. And I have a setup application to launch the .msi by CreateProcess with msiexec.exe command, and provide an UI. Currently, my requirement is get the detailed result of the installation – which drivers installed successfully, which failed. Since I can just get the result of CreateProcess, how can I retrieve the detailed result from the installation? Very appreciate if you can provide some information on this issue.

I created the .msi file with the difx:Driver flag like below:

<difx:Driver AddRemovePrograms="no" DeleteFiles="no" ForceInstall="no" Legacy="no" PlugAndPlayPrompt="no" />

An MSI-based setup is transactional. It either all works or all fails and rolls back the system to its previous state. It seems that you have made a choice to defeat this paradigm and have it partially succeed leaving some drivers installed and others not.

It also appears that you have suppressed the installer's UI so that error information cannot be found.

I have two recommendations:

  1. Don't use CreateProcess() and the "fire and forget" model. Use MsiSetExternalUIRecord with this model:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb309215(v=vs.85).aspx

There are C# p/invoke equivalents out there too. If you don't want to show all the UI then just collect the error messages and show them to the user if that's the goal. That's the only reliable way to get the actual error messages. This is the supported way for you to own the UI and collect only the messages that you think are important.

  1. Allow a failed driver install to fail the entire install and roll it all back. It might actually be like this already. If the install partially succeeds and four drivers are not installed, what's the plan? You can't run the MSI again because it will go into repair/maintenance mode. If the user needs to fix something and do the install again then the product needs to be uninstalled anyway.

You can retrieve the verbose installation log using the /L*V parameter:

msiexec /i "C:\MyPackage\Example.msi" /L*V "C:\log\example.log"

You can read more here .

The general structure is:

msiexec.exe [/i][/x] <path_to_package> [/L{i|w|e|a|r|u|c|m|o|p|v|x+|!|*}][/log] 

/L - enable logging i - include status messages w - include non-fatal warnings e - include all error messages a - mention when an action is started r - include action-specific records u - include user requests c - include the initial UI parameters m - include out-of-memory or fatal exit information o - include out-of-disk-space messages p - include terminal properties v - verbose output x - include extra debugging information + - append to an existing log file ! - flush each line to the log * - log all information, except for v and x options

Another simpler method, instead of parsing the log, would be to write a small C# custom action to check if the drivers are installed on the machine.

You need to schedule that custom action close the end of the installation process, as deferred (not immediate).

You can generate a log (as suggested by Harsh) or you can create a custom action (either deferred as suggested by Bogdan if you are using the method he suggests) or sequenced after InstallFinalize (if you have some other method that doesn't require elevation), but that custom action would probably need to use some sort of IPC to communicate what it finds back to your program.

One possibility for IPC might be the MsiProcessMessage function in your custom action with the INSTALLMESSAGE_INFO message type (what you send will also show up in the log) that you can receive in your application, but that will require using the MsiSetExternalUIRecord function which will require replacing your CreateProcess calling msiexec with something from the Installation and Configuration Functions section of that page.

Or if writing custom actions isn't where you need to go it may be easier for you to call MsiGetFeatureState or MsiGetComponentState with MsiOpenProduct , assuming that gives you the granularity of detail you're after.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM