获取产品名称从C#msi文件 [英] Get product name from msi file in C#

查看:201
本文介绍了获取产品名称从C#msi文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有安装的应用程序MSI文件。我前需要知道应用程序的的产品名称的安装开始。

I have an msi file that installs an application. I need to know the product name of that application before the installation starts.

我试过如下:

{ 

...
Type type = Type.GetType("Windows.Installer");
WindowsInstaller.Installer installer = (WindowsInstaller.Installer)
Activator.CreateInstance(type);

installer.OpenDatabase(msiFile, 0); //this is my guess to pass in the msi file name...
...
}

但现在呢?类型为的的,这引发了我的错误。而且我在哪里传中,MSI文件?

but now? Type is null, which throws me an error. And where do I pass in the name of the MSI file?

感谢您的任何提示和放大器;注释。

Thanks for any hints & comments.

推荐答案

您需要使用:

        Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

下面是我的一些code的样本 - 在我的情况,我得到了安装程序版本:

Here is a sample from some of my code - in my case I get the installer version:

        // Get the type of the Windows Installer object
        Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

        // Create the Windows Installer object
        Installer installer = (Installer)Activator.CreateInstance(installerType);

        // Open the MSI database in the input file
        Database database = installer.OpenDatabase(inputFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

        // Open a view on the Property table for the version property
        View view = database.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'");

        // Execute the view query
        view.Execute(null);

        // Get the record from the view
        Record record = view.Fetch();

        // Get the version from the data
        string version = record.get_StringData(2);

这篇关于获取产品名称从C#msi文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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