问题
I would like to know if a package is being installed/upgraded.
MSI engine sets a global mutex but doesn't relate to the product.
One idea I have is to scan running msiexec instances and check the command line parameters to determine the msi file and scan for its product code, but I would like to see if there is a better option although couldn't find any suitable API.
Thanks
回答1:
Major Upgrade: If your MSI is performing a major upgrade, then the product code of the previous version will be added to the property specified as the ActionProperty in the Upgrade table of the newest package. In WiX this property is generally called WIX_UPGRADE_DETECTED
by convention, but it can be called anything.
In other words, checking whether WIX_UPGRADE_DETECTED
or an equivalent property has any value at all can be used to detect that an upgrade is taking place.
UPGRADINGPRODUCTCODE: In the older setup - the one that is being uninstalled during the major upgrade - the built-in MSI property (as opposed to one you declare) UPGRADINGPRODUCTCODE
will be set to the product code of the newer setup. In other words you can use this property (UPGRADINGPRODUCTCODE
) in conditions in the old package, but it will not be set in the newer setup. This is a very common confusion.
Finding Installed Product: You can get the product code for an installed product easily: How can I find the product GUID of an installed MSI setup? The MSI API features a lot of methods and properties that can be used to determine pretty much whatever you want about an installed MSI. It can be accessed via COM, Win32, Managed code.
UPDATE: the script here shows how to identify related products by means of the MSI API RelatedProducts call. Towards bottom.
Some Links:
- Run Wix Custom action only during uninstall and not during Major upgrade (more elaborate description of the properties mentioned above - different words and formatting)
- MSI Tip: Informing the User When a Major Upgrade Will Take Place (Flexera)
- wix installer update process and confirmation dialog (An implementation in VBScript - of all things - showing a dialog to the user on major upgrade. I would not recommend this, but it is just a sample).
- check for windows installer mutex availability
回答2:
Because I want to detect what is Windows Installer installing but out-of-proc, this is what I did so far:
- Scan all processes and analyze all instances of
C:\Windows\System32\msiexec.exe
andC:\Windows\SysWow64\msiexec.exe
- Get the command-line parameter and check if
/I
was used. - Because the msi file specified in the command line may not contain a full path and the process' current directory may be different than the one when process was started, I used the following method to scan for the package.
- Using
VirtualQuery
andGetMappedFileName
scan the process looking for all memory mapped files - For each memory mapped file, try to open it using
MsiOpenDatabase
.MsiOpenPackage
won't work because the package is in use by the installer. - Run the SQL to get the
ProductCode
andUpgradeCode
from theProperty
table.
来源:https://stackoverflow.com/questions/52949144/programmatically-detect-msi-package-being-installed