2

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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Mauro H. Leggieri
  • 1,084
  • 11
  • 25
  • Added one more link to actual code that uses the MSI API. I can dig up further samples if need be, but don't want to "overlink" like I normally do. – Stein Åsmul Oct 28 '18 at 19:42
  • What type if sutable API do you want? You can take a snapshot and check the executable name msiexec.exe. – Biswapriyo Oct 28 '18 at 20:28

2 Answers2

2

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. Please see this answer for a better description of this confusion: Run Wix Custom action only during uninstall and not during Major upgrade

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:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
0

Because I want to detect what is Windows Installer installing but out-of-proc, this is what I did so far:

  1. Scan all processes and analyze all instances of C:\Windows\System32\msiexec.exe and C:\Windows\SysWow64\msiexec.exe
  2. Get the command-line parameter and check if /I was used.
  3. 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.
  4. Using VirtualQuery and GetMappedFileName scan the process looking for all memory mapped files
  5. For each memory mapped file, try to open it using MsiOpenDatabase. MsiOpenPackage won't work because the package is in use by the installer.
  6. Run the SQL to get the ProductCode and UpgradeCode from the Property table.
Mauro H. Leggieri
  • 1,084
  • 11
  • 25