确定第三方应用程序安装目录

sni*_*ker 7 c# installation wmi windows-installer

我有一个应用程序,在整个公司的数百台计算机上使用,我必须修改应用程序的安装目录中的INI文件.用户可以随意安装应用程序,并且可以在任何给定时间安装多个版本的应用程序.我需要能够找到该安装目录.

到目前为止我考虑过的方法:

  • 使用WindowsInstaller按名称查找产品并查找其安装目录.(从这里). - 这几乎可以工作,但我希望填充的属性(TARGETDIR,APPDIR)不是.
  • 查看注册表以查找特定应用程序的安装目录.它不在那里.
  • MsiGetComponentPath()?我在上面提到的相同链接中看到了这个,但我不知道如何实现它.我可以使用Windows安装程序获取ProductID,但我不知道如何以编程方式选择一个组件并随机查找其ID.任何人?

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

sni*_*ker 7

好吧,我想出了一个适合我的解决方案:

        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");
            }
        }
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,如果有人想知道"安装程序"引用了什么DLL,它位于C:\ windows\system32\msi.dll中. (5认同)