Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
933 views
in Technique[技术] by (71.8m points)

windows installer - Retrieving version of an MSI file (built with WiX)

I've created an MSI file with WiX. The source WiX file contains the version information like this:

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

The MSI file seem to work OK: it installs, it uninstalls, it upgrades when I increase the version number, etc.

However, when I attempt to get the version information about this file by calling the MsiGetFileVersion() API, it returns error 1006 (ERROR_FILE_INVALID File does not contain version information.)

Hence my question: how to (programmatically, in C++) retrieve the version number of an MSI file? Or, to put it another way, where in the WiX file should the version information go in order to be retrievable via MsiGetFileVersion()?

More information: The same error occurs with MSI 3.0 on Windows XP and MSI 4.0 on Vista.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For reference, here's a VBscript example that I'm using in my build process to grab such prior to creating a 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 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...