我用WiX创建了一个MSI文件。源WiX文件包含如下版本信息:

<Product Id="..." 
         Name="..." 
         Language="1033" 
         Version="1.0.0.1" 
         Manufacturer="..." 
         UpgradeCode="...">

MSI文件似乎工作正常:它安装,卸载,升级时增加版本号等等。

但是,当我尝试通过调用MsiGetFileVersion()API获取有关此文件的版本信息时,它返回错误1006(ERROR_FILE_INVALID  文件不包含版本信息。)

因此我的问题:如何(以编程方式,在C ++中)检索MSI文件的版本号?或者,换句话说,在WiX文件中,版本信息应该通过MsiGetFileVersion()来检索吗?

更多信息:Windows XP上的MSI 3.0和Vista上的MSI 4.0也会出现同样的错误。

有帮助吗?

解决方案

为了完整起见,:: MsiGetFileVersion()是一个函数,它从PE文件(.exe或.dll)中读取Windows安装程序执行的相同方式的版本资源信息。这对于使用构建工具(例如 WiX工具集)非常重要,因此它们可以正确填充File / @ Version信息。它不会从MSI中获取版本信息。正如@sascha所示,您可以在Property表中查询“ProductVersion”和“ProductVersion”。或者你可以使用:: MsiGetProductProperty()来做同样的事情。

其他提示

作为参考,这是一个VBscript示例,我在构建过程中使用它来创建一个boostrapper之前抓取它。

Dim installer, database, view, result

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

Dim sumInfo  : Set sumInfo = installer.SummaryInformation("my.msi", 0)
sPackageCode =  sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code.

WScript.Echo getproperty("ProductVersion")
WScript.Echo getproperty("ProductVersion")
WScript.Echo sPackageCode
WScript.Echo 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 

找到解决方案:不要调用MsiGetFileVersion(),而是调用:

MSIHANDLE hProduct = NULL;
MsiOpenPackage( pszPath, &hProduct );

MsiGetProductProperty( hProduct, _T("ProductVersion"), pszVersion, &dwSizeVersion );

MsiCloseHandle( hProduct );

(省略错误处理)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top