1

I have some python script which generates information for some application database.

Now I need fetch supported platform for specified .msi file. Aim is to distinguish Win32 and x64 applications inside of .msi file.

I don't see anything useful from msiexec /? Which basically shows same thing as https://learn.microsoft.com/en-us/windows/desktop/msi/command-line-options

Marek R
  • 32,568
  • 6
  • 55
  • 140
  • Please check the Python code I found on github.com. Not sure it will work, not set up to test. – Stein Åsmul Mar 12 '19 at 18:19
  • 1
    Note that it may be important to more specific on what you mean by “Win32 and x64 applications.” Depending on your definition, they may differ with nothing in the .msi database you can check for, or differ only in subtle ways like conditions that include [VersionNT64](https://learn.microsoft.com/en-us/windows/desktop/msi/versionnt64). Or your definition may match perfectly the [Template Summary](https://learn.microsoft.com/en-us/windows/desktop/msi/template-summary) as mentioned in the answers below. – Michael Urman Mar 16 '19 at 03:44

3 Answers3

1

You could check the Template Summary of the Windows Installer object? Here's a VBScript example that you can convert to Python:

'create installer object
Set oInstaller = CreateObject("WindowsInstaller.Installer")
'open msi in read-only mode
Set oDatabase = oInstaller.OpenDatabase("C:\Temp\test.msi", 0)
Dim streamobj : Set streamobj = oDatabase.SummaryInformation(0) '0 = read only
'read PID_TEMPLATE (template summary)
MsgBox streamobj.Property(7)
Set streamobj = Nothing
Set oDatabase = Nothing
Set oInstaller = Nothing
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28
1

Suggestion: I am not a Python guy (no pun intended), but I like to pillage github.com whenever I need something like that. Here is what I found. And the github.com search randomly set to page 21.

import msilib
#import sys

db = msilib.OpenDatabase("setup.msi", msilib.MSIDBOPEN_READONLY)
print( db.GetSummaryInformation(0).GetProperty(7))

Bitness: The bitness information is kept in the Summary Information Stream for the MSI, and it is referred to as the Template value. You must parse it to determine if it is a 64-bit package. Valid values are described here. There are several flavors of 64-bit CPUs. Just scan for x64, Intel64, ARM64 as appropriate - x64 is the most common for desktop (I believe). See how Advanced Installer does it.


64-Bit Component Flag: A real giveaway for a 64-bit package is that any components marked as msidbComponentAttributes64bit (which adds 256, 0x0100 to the attribute flag) in the Attributes column of the Component table in the Component Table means that the MSI package has to be 64-bit to support such components.


MSI SDK: I will also mention that the MSI SDK binary MsiInfo.exe (%ProgramFiles(x86)%\Windows Kits) can read the Template value easily, and the MSI API sample WiSumInf.vbs can do the same.

Sample CMD:

MsiInfo.exe Test.msi

and

cscript.exe WiSumInf.vbs Test.msi

Further Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
1

Here is the code I'm currently using for this problem:

import msilib

def msi_is_for_x64_only(path):
    data_base = msilib.OpenDatabase(str(path), msilib.MSIDBOPEN_READONLY)
    try:
        info = data_base.GetSummaryInformation(0)
        template = info.GetProperty(msilib.PID_TEMPLATE)
        platform_string = template.decode("utf-8").split(';')[0]
        return {
            'Intel': False,
            '': False,
            'Intel ': False,
            'x64': True,
            'Intel64': True
        }[platform_string]
    finally:
        # with msilib.OpenDatabase(str(path), msilib.MSIDBOPEN_READONLY) as data_base:
        # can't be used here
        data_base.Close()
Marek R
  • 32,568
  • 6
  • 55
  • 140
  • Nice, maybe do a validation of the MSI using Orca to make sure all is OK in the summary stream? – Stein Åsmul Mar 20 '19 at 12:59
  • Thanks for feedback, but ORCA MSI Editor doesn't give me anything. I already verified this script works with known msi files. Also I have ready infrastructure in python so `msilib` is handy solution and ORCA MSI Editor requires extra work. – Marek R Mar 20 '19 at 13:32