Inno setup 如何在Inno安装程序中获取msi文件的文件版本

Inno setup 如何在Inno安装程序中获取msi文件的文件版本,inno-setup,Inno Setup,我知道GetFileVersion和GetStringFileInfo函数,但它们不适用于*.msi文件。。。有什么想法吗 #define AppVersion GetFileVersion("path\MyFile.msi") #define AppVersion GetStringFileInfo("path\MyFile.msi", "FileVersion") 我会像这样使用它: #define AppName "Google Chrome" #define AppName2 "Goo

我知道
GetFileVersion
GetStringFileInfo
函数,但它们不适用于
*.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}
#define AppVersion GetMsiVersion("path\GoogleChromeStandaloneEnterprise.msi")
我需要从
GoogleChromeStandaloneEnterprise.msi
文件获取文件版本


谢谢你,马丁,它很有魅力。。。 关于…;-)

您可以从预处理器调用的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 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}
#define AppVersion GetMsiVersion("path\GoogleChromeStandaloneEnterprise.msi")

代码基于