Take the 2-minute tour ×

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.


share|improve this question

3 Answers 3

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.

share|improve this answer

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

  <RemoveExistingProducts After="InstallValidate" />

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

Good Luck!

share|improve this answer
Sorry, I forgot to indicate that I need the install folder to find the old config file so I can read data out of it to copy into the new config file. I've edited the question to include that information. –  Tony Vitabile Sep 12 '11 at 14:33
up vote 0 down vote accepted

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.


share|improve this answer

Your Answer


