Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine 3rd Party Application Installation Directory

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.

like image 329
snicker Avatar asked Aug 20 '09 22:08

snicker


People also ask

Where is the installation directory in Windows 10?

Open File Explorer using Win+E hotkey. Access the drive where Windows is installed (usually, it is C Drive) Access Program Files/Program Files (x86) folder. There will be a folder with the program name.


2 Answers

Using WMI could work for some people, unfortunately our users won't have credentials allowing them to do this on their machines:

        ManagementObjectSearcher search = new ManagementObjectSearcher("Select InstallationLocation from Win32_Product");
        ManagementObjectCollection results = search.Get();

        foreach (ManagementObject mo in results)
        {
            Console.WriteLine(mo["InstallLocation"]);
        } 
like image 85
snicker Avatar answered Oct 18 '22 08:10

snicker


If the install is an MSI then getting the information from WMI is trivial. The Win32_Product class has an InstallLocation property to hold this information.

like image 35
EBGreen Avatar answered Oct 18 '22 08:10

EBGreen