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:
Alright, lets hear any other methods for programmatically determining the installation directory of a Windows application.
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.
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"]);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With