views:

90

answers:

2

Context: I have a handful of plug-ins (which are really just DLLs with a different extension) that need to be installed in a sub-folder of a 3rd party application. Usually it's enough to simply copy them to said folder, but occasionally there are other libraries that need to be installed as well. I'd like to make this process less error-prone for users so I've looked in to using an installer project in visual studio to create a .msi, but I'm having trouble getting the install location configured correctly.

It seems that it assumes the installer is meant for a complete application and defaults to a location such as C:\Program Files\MyApp\, but what I really need is C:\Program Files\\Plugins. I'd rather not assume that the user has the 3rd party application installed in any particular location, so what I'd like is a way to locate where this other application has been installed. I've searched through Microsoft's documentation and experimented a bit on my own, but haven't had any success.

Assuming this is possible, does anyone know how to accomplish what I want?

A: 

Most applications will write their installation location somewhere in the registry. We read values under the following registry key to find the Microsoft Word install location.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe]

Unfortunately there's no standard way to retrieve the installation location of a particular application. You'll have to search the registry to find what you want.

sascha
A: 

If your application used the Windows installer you can try this method (C#):

    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("<YOUR PRODUCT NAME HERE>"))
        {
            string installdir = msi.get_ProductInfo(productcode, "InstallLocation");
            Console.WriteLine("{0}: {1} @({2})", productcode, productname, installdir);
        }
    }
snicker