简体   繁体   中英

How to determine the folder that a previous WIX Install installed a program in

The existing installer for our product does not write any information to the registry, nor does it write any custom environment variables. The user is allowed to change the install directory in the installer's UI. When I'm doing an upgrade, how do I find out what folder the previous version was installed into?

I need to know the folder so I can find the previous configuration file & copy values from it. The new version's configuration file has new tags and a new structure, so I can't just keep the previous file & reuse it.

Tony

MSI doesn't have that information directly. (MSI packages can have multiple "root" directories, so there's no telling which one a developer might want.) If you have the directory in the registry, use RegistrySearch . Otherwise, you can use MsiGetComponentPath in a custom action.

I've done some research into this and here's the solution that I came up with:

When the installer finishes installing, it creates a node in the registry under the path

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\<Product ID>

for 32 bit installs on 32 bit OS or 64 bit installs on 64 bit OS, or

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\<Product ID>

for 32 bit installs on 64 bit OS.

This node contains a value called InstallLocation which gives you the path to where the executables are installed.

Unfortunately, the previous version of our installer did not set this property, so I can't use it. BUT our installer creates a Service. I have found the path to the node in the registry for that service. From there, I can retrieve the value of the ImagePath value and extract the path from the service's .EXE file name.

So my solution is to:

  1. Fix the new installer so it does set the InstallLocation value.
  2. When upgrading from the previous version only, it will retrieve the registry node for the service & use the service's ImagePath key.
  3. If upgrading from any later version, we'll retrieve the Uninstall node and use the InstallLocation key.

Tony

msiexec keeps a copy of the msi from the last install so it will handle uninstalling the previous version you will need to just include the InstallExecuteSequence section

<InstallExecuteSequence>
  <RemoveExistingProducts After="InstallValidate" />
</InstallExecuteSequence>

This will only work if you are using the same UpgradeCode attribute in your Product Element.

Good Luck!

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