2009-05-02 52 views
8

我已经使用WiX创建了一个MSI文件。源维克斯文件中包含这样的版本信息:检索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()进行检索?

更多信息:在Vista上,Windows XP和MSI 4.0上的MSI 3.0发生同样的错误。

回答

6

只是为了完整性起见,:: MsiGetFileVersion()是读取从PE文件(.exe或.dll)的相同方式Windows安装程序的版本资源信息的功能。这对于构建工具(如WiX toolset)的使用非常重要,以便它们正确地填充File/@版本信息。它不会从MSI获得版本信息。正如@sascha所示,您可以查询属性表中的“ProductVersion”,或者您可以使用:: MsiGetProductProperty()来执行相同的操作。

4

找到了解决办法:不是调用MsiGetFileVersion(),请致电:

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

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

MsiCloseHandle(hProduct); 

(处理省略错误)

7

仅供参考,下面是我用我的构建过程,以一个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 
+0

Saschabeaunont - 任何双WScript.Echo getproperty(“ProductVersion”)的原因? – user66001 2013-07-26 01:22:25

+0

另外 - 对于那些需要更多MSI信息的人,请看看这个小宝石 - http://stackoverflow.com/questions/5063129/how-to-find-the-upgrade-code-productcode-of-an-installed -application-in-win-7/17871498#17871498 – user66001 2013-07-26 05:31:42