2009-05-02 54 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