github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/packaging/msi/msi_product_code.ps1 (about)

     1  # Copyright 2023 Tetrate
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # msi_product_code.ps1 gets the ProductCode (wix Product.Id) from the given MSI file.
    16  # This must be invoked with Windows.
    17  #
    18  # Ex powershell -File ./packaging/msi/msi_product_code.ps1 -msi /path/to/wazero.msi
    19  #
    20  # See https://docs.microsoft.com/en-us/windows/win32/msi/product-codes
    21  param ([string]$msi)
    22  
    23  $windowsInstaller = New-Object -com WindowsInstaller.Installer
    24  
    25  # All the below chain from this OpenDatabase
    26  # See https://docs.microsoft.com/en-us/windows/win32/msi/installer-opendatabase
    27  $database = $windowsInstaller.GetType().InvokeMember(
    28    "OpenDatabase", "InvokeMethod", $Null, $windowsInstaller, @($msi, 0)
    29  )
    30  
    31  # We need the ProductCode, which is what wxs Product.Id ends up as:
    32  # See https://docs.microsoft.com/en-us/windows/win32/msi/productcode
    33  $q = "SELECT Value FROM Property WHERE Property = 'ProductCode'"
    34  $View = $database.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $database, ($q))
    35  
    36  try {
    37    # https://docs.microsoft.com/en-us/windows/win32/msi/view-execute
    38    $View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null) | Out-Null
    39  
    40    $record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
    41    $productCode = $record.GetType().InvokeMember("StringData", "GetProperty", $Null, $record, 1)
    42  
    43    Write-Output $productCode
    44  } finally {
    45    if ($View) {
    46      $View.GetType().InvokeMember("Close", "InvokeMethod", $Null, $View, $Null) | Out-Null
    47    }
    48  }