Having the product code or the product name of an application, how can I find the location where this application is installed? There must be somewhere this information, because Windows uninstallation knows which folder to remove. I hoped it would be under the Registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall{ProductCode}, but the location is not there. I searched the entire registry, but I could not find it. Do you know how I can find the location? And if you have some .NET code doing this, that would be even better.
2 Answers
If you have the product code, you can use it in a call to MsiGetProductInfo. This call might be able to tell you the INSTALLPROPERTY_INSTALLLOCATION, or it can tell you the INSTALLPROPERTY_LOCALPACKAGE, which you can then use with MsiOpenDatabase to find its components. Once you have access to its components, you can call MsiGetComponentPath to locate its key file. Eventually one of the components should be able to tell you what you need to know.
If you know the component ahead of time, you can skip most of the steps. And if this is from within another package, you could use a CompLocator based search to find it without writing a custom action.
If you have to use .NET code to do this, you can either make P/Invoke wrappers for those functions, use existing ones like those in DTF, or see if the COM-accessible Windows Installer Automation Interface exposes the right APIs.

- 1
- 1

- 15,737
- 2
- 28
- 44
The question is a little vague because there is usually no single location where an app is installed. But if you are referring to the main "application folder" that the user can typically change, then it might be stored. However, that install location is in the registry (and available from MsiGetProductInfo) only if the setup makes it happen. The setup must set ARPINSTALLLOCATION to (usually) TARGETDIR for Windows to store it.
Otherwise, as Michael says, find a component ID from the product and get its path. However if you are creating an install and need to install something to that location then you don't need code. Most setup tools have a component search that can be used to set an install directory for your files.

- 20,260
- 1
- 18
- 28