如何以编程方式读取 MSI 文件中的属性? [英] How can I programmatically read the properties inside an MSI file?

查看:26
本文介绍了如何以编程方式读取 MSI 文件中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法读取 MSI 文件中的属性?

Is there a way to read the properties inside an MSI file?

例如,给定一个名为 Testpackage.msi 的 MSI 文件,我需要找到

For example, given a MSI file named Testpackage.msi, I need to find

productName
PackageCode
version

这我将与 WMI 卸载一起使用

This I am going to use it with WMI uninstall

string objPath = string.Format("Win32_Product.IdentifyingNumber='{0}', Name='{1}', Version='{2}'", "{AC9C1263-2BA8-4863-BE18-01232375CE42}", "testproduct", "10.0.0.0");

使用 Orca 是一种很好的选择,如果这可以通过编程实现.然后我可以使用它来生成自动发行说明.在卸载程序中也是如此.

Using Orca is a great option, if this can be achieved programmatically. Then I can use this to generate automatic release notes. And in un-installing program too.

推荐答案

您可以使用 用于处理 MSI 的基于 COM 的 API,并执行类似的操作

You can use the COM-based API for working with MSI, and do something like

Function GetVersion(ByVal msiName)

    Const msiOpenDatabaseModeReadOnly = 0
    Dim msi, db, view

    Set msi = CreateObject("WindowsInstaller.Installer")
    Set db = msi.OpenDataBase(msiName, msiOpenDatabaseModeReadOnly)
    Set view = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'")
    Call view.Execute()

    GetVersion = view.Fetch().StringData(1)

End Function

这篇关于如何以编程方式读取 MSI 文件中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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