如何在Inno Setup中获取MSI文件的文件版本 [英] How to get file version of msi file in Inno Setup

查看:187
本文介绍了如何在Inno Setup中获取MSI文件的文件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道GetFileVersionGetStringFileInfo函数,但是它们不适用于*.msi文件...知道吗...?

I know GetFileVersion and GetStringFileInfo functions, but they do not work with *.msi files... Any idea...?

#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文件获取文件版本.

I need get file version from GoogleChromeStandaloneEnterprise.msi file.

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

Thanks Martin, it works like a charm... Regards... ;-)

推荐答案

您可以使用从预处理器调用的PowerShell中="=" nofollow noreferrer> WindowsInstaller.Installer :

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]

使用方式如下:

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


代码基于如何使用PowerShell查找MSI产品版本号?

这篇关于如何在Inno Setup中获取MSI文件的文件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆