1

I want to get the product code from an msi file before installing it. I need it to remove the other version of a product if it's already installed on my computer. I mean I want to prevent an error 1638 ("Another version of this product already exists...") and to delete it manually in my code. I'm using c++. So I want to get the product code from the msi file that is about to install and using this product code remove the existing version of the product and install a new one. But when I'm trying to open an msi file to get it's handle using

MsiOpenPackage(msiPackagePath, &d_handle);

I get an error 1638. So I can not open an msi file and can not get a product code from it. My question: is it possible to get a product code from msi file not opening it with MsiOpenPackage? Thank you in advance!

brc-dd
  • 10,788
  • 3
  • 47
  • 67
Polina Bodnar
  • 171
  • 3
  • 15
  • 2
    Major upgrades are generally implemented via the Upgrade code. It should match between the two MSI versions. You author the [Upgrade table](https://learn.microsoft.com/en-us/windows/win32/msi/upgrade-table) with details on how you want the upgrade to work, and then the uninstall of the previous versions happens by built-in MSI mechanisms. [Find product code](https://stackoverflow.com/q/29937568/129130). [Find upgrade code](https://stackoverflow.com/q/46637094/129130). [**Debugging failed major upgrades**](https://stackoverflow.com/a/56991527/129130). – Stein Åsmul Jul 10 '20 at 14:16
  • I have samples for code access to the MSI, but don't have time to locate it right now. Do you really need it? Why are you going via C++? Are you invoking install from an application? – Stein Åsmul Jul 10 '20 at 14:23

1 Answers1

0

My colleague has just solved a problem. We used a function MsiOpenPackageEx and passed a flag MSIOPENPACKAGEFLAGS_IGNOREMACHINESTATE to ignore the computer state and return a handle anyway.

Polina Bodnar
  • 171
  • 3
  • 15
  • Why do you need to retrieve this when you can use a major upgrade and author the upgrade table to uninstall the previous version? What tool are you using to make the MSI? – Stein Åsmul Jul 11 '20 at 00:55