首页 文章

检索MSI文件的版本(使用WiX构建)

提问于
浏览
8

我用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也会出现相同的错误 .

3 回答

  • 4

    为了完整起见,:: MsiGetFileVersion()是一个函数,它以与Windows Installer相同的方式从PE文件(.exe或.dll)读取版本资源信息 . 这对于使用构建工具(例如WiX toolset)非常重要,因此它们可以正确填充File / @ Version信息 . 它不会从MSI中获取版本信息 . 正如@sascha所示,您可以查询属性表中的"ProductVersion",或者您可以使用:: MsiGetProductProperty()来执行相同操作 .

  • 6

    作为参考,这是一个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
    
  • 7

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

    MSIHANDLE hProduct = NULL;
    MsiOpenPackage( pszPath, &hProduct );
    
    MsiGetProductProperty( hProduct, _T("ProductVersion"), pszVersion, &dwSizeVersion );
    
    MsiCloseHandle( hProduct );
    

    (错误处理省略)

相关问题