如何在Inno Setup中获取msi文件的文件版本

时间:2018-01-31 19:55:51

标签: inno-setup

我知道GetFileVersionGetStringFileInfo个函数,但它们不适用于*.msi个文件......任何想法......?

#define AppVersion GetFileVersion("path\MyFile.msi")
#define AppVersion GetStringFileInfo("path\MyFile.msi", "FileVersion")

我就像使用它一样:

#define AppName "Google Chrome"
#define AppName2 "Google Chrome x86/x64"
#define AppVersion GetFileVersion("path\GoogleChromeStandaloneEnterprise.msi")
#define AppExe "chrome.exe"

[Setup]
AppName={#AppName}
AppVerName={#AppName2} v{#AppVersion}
AppVersion={#AppVersion}
VersionInfoVersion={#AppVersion}

我需要从GoogleChromeStandaloneEnterprise.msi文件获取文件版本。

感谢马丁,它就像一个魅力...... 问候......; - )

1 个答案:

答案 0 :(得分:0)

You can use WindowsInstaller.Installer from a PowerShell invoked from the preprocessor:

#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]

Use it like:

#define AppVersion GetMsiVersion("path\GoogleChromeStandaloneEnterprise.msi")

The code is based on How do I find the MSI product version number using PowerShell?