Retrieving version of an MSI file (built with WiX)

后端 未结 3 959
刺人心
刺人心 2020-12-16 23:06

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



        
相关标签:
3条回答
  • 2020-12-16 23:19

    Found a solution: instead of calling MsiGetFileVersion(), call:

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

    (error handling omitted)

    0 讨论(0)
  • 2020-12-16 23:27

    Just for completeness sake, ::MsiGetFileVersion() is a function that reads the version resource information from a PE file (.exe or .dll) the same way the Windows Installer does. That is important for build tools (such as the WiX toolset) to use so they populate the File/@Version information correctly. It will not get you the version information out of an MSI. As @sascha shows you could query the Property table for the "ProductVersion" or you could use the ::MsiGetProductProperty() which will do the same.

    0 讨论(0)
  • 2020-12-16 23:31

    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 
    
    0 讨论(0)
提交回复
热议问题