Determine the third-party application installation directory

advertisements

I have an application that is used on several hundred computers across the company that I must modify an INI file in the installation directory of the application. Users can install the application where ever they wish, and can have multiple versions of the application installed at any given time. I need to be able to find that installation directory.

Methods I've considered so far:

  • Using the WindowsInstaller to find the product by name and find its installation directory. (from here). --This almost worked, but the properties I'd expect to be populated (TARGETDIR, APPDIR) aren't.
  • Looking through the registry to find the installation directory for the particular app. It's not in there.
  • MsiGetComponentPath()? I saw this in the same link mentioned above, but I don't know how to implement it. I can get the ProductID using windows installer, but I don't know how to programmatically just choose a component and find its ID at random. Anyone?

Alright, lets hear any other methods for programmatically determining the installation directory of a Windows application.


Well I came up with a solution that worked for me:

        Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
        Installer msi = (Installer)Activator.CreateInstance(type);
        foreach (string productcode in msi.Products)
        {
            string productname = msi.get_ProductInfo(productcode, "InstalledProductName");
            if (productname.Contains("<APPLICATION NAME>"))
            {
                string installdir = msi.get_ProductInfo(productcode, "InstallLocation");
            }
        }