您可以使用WindowsInstaller.Installer https://learn.microsoft.com/en-us/windows/win32/msi/installer-object从预处理器调用的 PowerShell:
#define GetMsiVersion(str FileName) \
Local[4] = ExtractFileName(FileName), \
Local[0] = AddBackslash(GetEnv("TEMP")) + Local[4] + ".ver", \
Local[1] = \
"-ExecutionPolicy Bypass -Command """ + \
"Write-Host 'Retrieving version of MSI " + Local[4] + "'; " + \
"$windowsInstaller = New-Object -com WindowsInstaller.Installer; " + \
"$database = $windowsInstaller.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $windowsInstaller, @('" + FileName + "', 0)); " + \
"$q = 'SELECT Value FROM Property WHERE Property = ''ProductVersion'''; " + \
"$view = $database.GetType().InvokeMember('OpenView', 'InvokeMethod', $Null, $database, ($q)); " + \
"$view.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $view, $Null); " + \
"$record = $view.GetType().InvokeMember('Fetch', 'InvokeMethod', $Null, $view, $Null); " + \
"$productVersion = $record.GetType().InvokeMember('StringData', 'GetProperty', $Null, $record, 1); " + \
"$view.GetType().InvokeMember('Close', 'InvokeMethod', $Null, $view, $Null); " + \
"Set-Content -Path '" + Local[0] + "' -Value $productVersion;" + \
"""", \
Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
Local[2] = FileOpen(Local[0]), \
Local[3] = FileRead(Local[2]), \
FileClose(Local[2]), \
DeleteFileNow(Local[0]), \
Local[3]
像这样使用它:
#define AppVersion GetMsiVersion("path\GoogleChromeStandaloneEnterprise.msi")
该代码基于如何使用 PowerShell 查找 MSI 产品版本号? https://stackoverflow.com/q/8743122/850848