我有一个应用程序在公司的数百台计算机上使用,我必须修改应用程序安装目录中的 INI 文件。用户可以随心所欲地安装该应用程序,并且可以在任何给定时间安装该应用程序的多个版本。我需要能够找到该安装目录。
到目前为止我考虑过的方法:
- 使用 WindowsInstaller 按名称查找产品并找到其安装目录。 (来自 here)。 -- 这几乎成功了,但我期望填充的属性(TARGETDIR、APPDIR)却没有。
- 通过注册表查找特定应用程序的安装目录。它不在那里。
- MsiGetComponentPath()?我在上面提到的同一个链接中看到了这个,但我不知道如何实现它。我可以使用 Windows 安装程序获取 ProductID,但我不知道如何以编程方式选择一个组件并随机找到它的 ID。有人吗?
好吧,让我们听听其他以编程方式确定 Windows 应用程序安装目录的方法。
最佳答案
好吧,我想出了一个对我有用的解决方案:
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");
}
}
关于c# - 确定第 3 方应用程序安装目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1309142/