Search code examples
windows-installerinstallshield

Use installed app's location as a default path during a major upgrade


I have an application which I am writing a major upgrade for.
The only thing that is persistent is an UpgradeCode. What I want is to use a location of a previously installed version as a default path for installation.

My naive solution is to run a CustomAction which modifies the INSTALLDIR with a variable APP_LOCATION obtained by AppSearch table.

  1. Is there a conventional way to achive that via means on MSI or InstallShield?
  2. Can I use a condition in an MSI table to use "APP_LOCATION" from AppSearch table if it contains value? For example: INSTALLDIR = APP_LOCATION ? APP_LOCATION : MY_DEFAULT_INSTALL_DIR (syntax is to emphasize the logic, idk if is valid)

Solution

  • You can fetch previous install location using the following method:

    Msi.GetProductInfo(ProductCode of previous Install, "InstallLocation");

    To get the product code of previous installation, Use the public property set for the major upgrade. This public property for example OLD_PRODUCT_DETECTED property can be found in ActionProperty column of Upgrade table. It's value will be set to product code({GUID}).

    Make sure to call the above method after FindRelatedProducts action which sets the value for public property to {GUID} if previous installation found.