确定第三方应用程序安装目录 [英] Determine 3rd Party Application Installation Directory

查看:293
本文介绍了确定第三方应用程序安装目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是在几百台计算机对面,我必须在应用程序的安装目录修改INI文件,公司使用的应用程序。用户可以安装在以往他们希望的应用,并且可以安装在任何给定时间的应用程序的多个版本。我需要能够找到安装目录

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?

好吧,让我们听到编程方式确定一个Windows应用程序的安装目录中的任何其他方法。

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");
            }
        }

这篇关于确定第三方应用程序安装目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆