代码之家  ›  专栏  ›  技术社区  ›  snicker

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

  •  7
  • snicker  · 技术社区  · 17 年前

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

    • 使用WindowsInstaller按名称查找产品并查找其安装目录。(来自 here ).
    • 在注册表中查找特定应用程序的安装目录。它不在里面。
    • MsiGetComponentPath()?我在上面提到的同一个链接中看到了这一点,但我不知道如何实现它。我可以使用windows installer获得ProductID,但我不知道如何通过编程选择一个组件并随机查找其ID。任何人

    3 回复  |  直到 9 年前
        1
  •  8
  •   snicker    17 年前

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

            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");
                }
            }
    
        2
  •  2
  •   snicker    17 年前

    使用WMI可能适用于某些人,但不幸的是,我们的用户没有允许他们在其计算机上执行此操作的凭据:

            ManagementObjectSearcher search = new ManagementObjectSearcher("Select InstallationLocation from Win32_Product");
            ManagementObjectCollection results = search.Get();
    
            foreach (ManagementObject mo in results)
            {
                Console.WriteLine(mo["InstallLocation"]);
            } 
    
        3
  •  1
  •   EBGreen    17 年前

    如果安装是MSI,那么从WMI获取信息是微不足道的。Win32_产品类具有用于保存此信息的InstallLocation属性。