如何以编程方式读取 MSI 文件内的属性?

发布于 2024-07-09 05:39:25 字数 622 浏览 8 评论 0原文

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

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

productName
PackageCode
version

此文件,我将在 WMI 卸载中使用它

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

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

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

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

productName
PackageCode
version

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");

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那片花海 2024-07-16 05:39:25

您可以使用基于 COM 的 API 来处理 MSI< /a>,然后做类似的事情

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

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
独留℉清风醉 2024-07-16 05:39:25

WiX 工具集WiX 快速入门技巧(资源链接集合)。 WiX 安装 DTF。


我只想提一下,现在事情变得更加容易了。 Windows Installer 对象模型有一个完整的 .NET 包装器,因此您可以避免任何 COM 互操作的笨拙

DTF - 入门:主文件:Microsoft.Deployment.WindowsInstaller.dll

  1. 下载并安装 WiX 工具包
  2. WixInstallPath\SDK 目录中找到以下文件

该包装器称为“部署工具基础”(DTF),以下是基本描述:“部署工具基础是一组丰富的 .NET 类库和相关资源,它们将 Windows它旨在大大​​简化与部署相关的开发任务,同时仍然公开底层技术的完整功能。”。

这是一个精简的实践示例

using (var db = new Database(FullPath, DatabaseOpenMode.ReadOnly))
{    
  PackageCode = db.SummaryInfo.RevisionNumber;
  AppVendor = db.SummaryInfo.Author;
  AppName = db.SummaryInfo.Title;
  ProductName = db.SummaryInfo.Subject;
  ProductCode = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 "`Property` WHERE `Property` = 'ProductCode'");
  AppVersion = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 "`Property` WHERE `Property` = 'ProductVersion'");
  UpgradeCode = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 " `Property` WHERE `Property` = 'UpgradeCode'");
}

主要 DTF 文件(后两个是最常用的文件):

  • Microsoft.Deployment.Compression.dll - 归档打包和解包的框架。
  • Microsoft.Deployment.Compression.Cab.dll - 实现压缩包打包和解包。
  • Microsoft.Deployment.Resources.dll - 用于在可执行文件中读取和写入资源数据的类。
  • Microsoft.Deployment.WindowsInstaller.dll - 用于 Windows Installer API 的完整的基于 .NET 的类库。
  • Microsoft.Deployment.WindowsInstaller.Package.dll - 用于处理 Windows Installer 安装和修补程序包的扩展类。

只需创建一个 C# 项目,引用这些文件,并使用您想要和需要的任何控件编写您自己的部署应用程序。 我目前尚未设置 DTF 工具,但请参阅此示例 C# 程序如何工作的一般概念。

  • DTF 包含在 WIX 中。 从此处下载 WiX
  • DTF dll 位于 WiX 主安装文件夹的 SDK 文件夹中(默认位置为:%ProgramFiles(x86)%\WiX Toolset v3.10\SDK)。 当您看到此内容时,版本号可能会有所不同。 只需在 %ProgramFiles(x86)% 下查找 WiX 文件夹即可。
  • 在“doc”文件夹中查找DTF 帮助文件DTF.chmDTFAPI.chm。 关于对象模型及其用法的绝对优秀的文档。
  • 有关更多 DTF 详细信息,请参阅此 serverfault.com 帖子
  • 使用 WiX 的一些入门建议

WiX toolset: WiX quick-start tips (collection of links to resources). WiX installs DTF.


I just want to mention that things have gotten even easier now. There is a full .NET wrapper for the Windows Installer object model, so you can avoid any COM interop clunkiness.

DTF - Getting Started: Main file: Microsoft.Deployment.WindowsInstaller.dll

  1. Download and install the WiX toolkit
  2. Find the files below in the WixInstallPath\SDK directory

The wrapper is called "Deployment Tools Foundation" (DTF) and here is the basic description: "Deployment Tools Foundation is a rich set of .NET class libraries and related resources that together bring the Windows deployment platform technologies into the .NET world. It is designed to greatly simplify deployment-related development tasks while still exposing the complete functionality of the underlying technology".

Here is a stripped-down, hands-on sample:

using (var db = new Database(FullPath, DatabaseOpenMode.ReadOnly))
{    
  PackageCode = db.SummaryInfo.RevisionNumber;
  AppVendor = db.SummaryInfo.Author;
  AppName = db.SummaryInfo.Title;
  ProductName = db.SummaryInfo.Subject;
  ProductCode = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 "`Property` WHERE `Property` = 'ProductCode'");
  AppVersion = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 "`Property` WHERE `Property` = 'ProductVersion'");
  UpgradeCode = (string)db.ExecuteScalar("SELECT `Value` FROM "+
                 " `Property` WHERE `Property` = 'UpgradeCode'");
}

Primary DTF files (the latter two are the most used ones):

  • Microsoft.Deployment.Compression.dll - Framework for archive packing and unpacking.
  • Microsoft.Deployment.Compression.Cab.dll - Implements cabinet archive packing and unpacking.
  • Microsoft.Deployment.Resources.dll - Classes for reading and writing resource data in executable files.
  • Microsoft.Deployment.WindowsInstaller.dll - Complete .NET based class library for the Windows Installer APIs.
  • Microsoft.Deployment.WindowsInstaller.Package.dll - Extended classes for working with Windows Installer installation and patch packages.

Just create a C# project, reference these files, and code your own deployment application with whatever control you desire and need. I am not set up with the tools for DTF at the moment, but see this sample for a general idea of how a C# program would work.

  • DTF is included with WIX. Download WiX from here.
  • The DTF dlls are in the SDK folder in the main WiX installation folder (the default location is: %ProgramFiles(x86)%\WiX Toolset v3.10\SDK). The version number will probably be different by the time you see this. Just look for the WiX folder under %ProgramFiles(x86)%.
  • Look for the DTF help files in the "doc" folder. DTF.chm and DTFAPI.chm. Absolutely excellent documentation for the object model and its usage.
  • See this serverfault.com post for some more DTF details
  • Some starter suggestions for working with WiX
晨曦÷微暖 2024-07-16 05:39:25

您可以使用Microsoft 的 Orca.exe。 Orca 将允许您打开 MSI 并编辑/查看其中的所有表。 您必须下载整个 Windows SDK为了得到它,但幸运的是这是免费的。

一种替代方案(由于 SDK 的下载大小可能会更快)是使用 WiX 项目。 Dark 是一个 MSI 反编译器,它将所有内容导出到 XML 文件和资源集合中。 它输出的 XML 将包含您正在查找的信息。

You can use Microsoft's Orca.exe. Orca will allow you to open the MSI and edit/view all the tables in it. You will have to download the entire Windows SDK in order to get it, but thankfully that is free.

One alternative (which might be faster due to the download size of the SDK) is to use dark.exe from the WiX project. Dark is a MSI decompiler, which will export everything into an XML file and collection of resources. The XML it outputs will have the information you are looking for.

美人骨 2024-07-16 05:39:25

这是 VBScript 中的一个类似示例,我将其用作创建引导程序可执行文件的构建过程的一部分...

Option Explicit
Const MY_MSI = "product.msi"

Dim installer, database, view, result, sumInfo, sPackageCode

Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (MY_MSI, 0)

Set sumInfo = installer.SummaryInformation(MY_MSI, 0)
sPackageCode =  sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code.

WScript.Echo "ProductVersion=" & getproperty("ProductVersion")
WScript.Echo "ProductCode=" & getproperty("ProductCode") 
WScript.Echo "PackageCode=" & sPackageCode 
WScript.Echo "ProductName=" & getproperty("ProductName") 

Function getproperty(property)

    Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='" & property & "'")
    view.Execute
    Set result = view.Fetch
    getproperty = result.StringData(1)

End Function 

Here's a similar example in VBScript which I use as part of my build process in creating bootstrapper executables...

Option Explicit
Const MY_MSI = "product.msi"

Dim installer, database, view, result, sumInfo, sPackageCode

Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase (MY_MSI, 0)

Set sumInfo = installer.SummaryInformation(MY_MSI, 0)
sPackageCode =  sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code.

WScript.Echo "ProductVersion=" & getproperty("ProductVersion")
WScript.Echo "ProductCode=" & getproperty("ProductCode") 
WScript.Echo "PackageCode=" & sPackageCode 
WScript.Echo "ProductName=" & getproperty("ProductName") 

Function getproperty(property)

    Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='" & property & "'")
    view.Execute
    Set result = view.Fetch
    getproperty = result.StringData(1)

End Function 
沉默的熊 2024-07-16 05:39:25

我在 lessmsi 中找到了一个轻量级非编程解决方案。 它显然使用 wix 并将整个 .msi 分解到指定的文件夹中。 (它也有一个 UI,但在 Win7 上对我来说效果不太好)。

I found a lightweight non-programmatic solution in lessmsi. It apparently uses wix and just explodes the whole .msi into a specified folder. (It also has a UI but it didn't render great for me on Win7).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文