确定第三方应用程序安装目录 [英] Determine 3rd Party Application Installation Directory
问题描述
我有一个是在几百台计算机对面,我必须在应用程序的安装目录修改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:
- 使用WindowsInstaller按名称查找产品并找到它的安装目录。 (从这里 )。
- 这几乎工作,但我期望的属性填充(TARGETDIR,APPDIR)都没有。 - 通过注册表希望找到安装目录在特定的应用程序。这不是在那里。
- MsiGetComponentPath()?我在上面提到的相同的链接看到了这一点,但我不知道如何实现它。我能得到的ProductID使用Windows Installer,但我不知道如何编程只是选择一个组件,随机找到其ID。有人吗?
- 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屋!