gpt4 book ai didi

command-line - 如何在Inno Setup中执行cmd命令

转载 作者:行者123 更新时间:2023-12-02 05:51:39 36 4
gpt4 key购买 nike

为了静默安装 MySQL,我尝试在 cmd 中执行以下命令,它工作正常:

msiexec /i "mysql-essential-6.0.11-alpha-winx64.msi" /qn

但是,如何在 Inno Setup 中安装之前运行该命令?

最佳答案

您可以通过调用 Exec 来执行它来自 CurStepChanged 的函数事件方法,此时步骤将为ssInstall。下面的脚本显示了如何将 MySQL 安装程序包含到您的安装中以及如何在安装开始之前提取并执行它:

#define MySQLInstaller "mysql-essential-6.0.11-alpha-winx64.msi"

[Files]
Source: "{#MySQLInstaller}"; Flags: dontcopy
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
Params: string;
ResultCode: Integer;
begin
if (CurStep = ssInstall) then
begin
ExtractTemporaryFile('{#MySQLInstaller}');
Params := '/i ' + AddQuotes(ExpandConstant('{tmp}\{#MySQLInstaller}')) + ' /qn';
if not Exec('msiexec', Params, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
MsgBox('Installation of MySQL failed. Exit code: ' + IntToStr(ResultCode),
mbInformation, MB_OK);
end;
end;

利用未使用的进度条:

由于 MySQL 安装完成需要一些时间,并且您决定隐藏安装程序的用户界面(无论如何这也可能很不安全),因此您可以扩展脚本以使用进度条,即显示在安装过程中的起始位置,当时未使用。以下代码将(至少在 Windows XP 系统上)Inno Setup 的安装进度条切换为 marquee style并在状态标签中显示说明。当 MySQL 安装完成后,进度条切换回正常模式,并开始实际的 Inno Setup 安装:

#define MySQLInstaller "mysql-essential-6.0.11-alpha-winx64.msi"

[Files]
Source: "{#MySQLInstaller}"; Flags: dontcopy
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
Params: string;
ResultCode: Integer;
begin
if (CurStep = ssInstall) then
begin
WizardForm.ProgressGauge.Style := npbstMarquee;
WizardForm.StatusLabel.Caption := 'Installing MySQL. This may take a few minutes...';

ExtractTemporaryFile('{#MySQLInstaller}');
Params := '/i ' + AddQuotes(ExpandConstant('{tmp}\{#MySQLInstaller}')) + ' /qn';
if not Exec('msiexec', Params, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
MsgBox('Installation of MySQL failed. Exit code: ' + IntToStr(ResultCode),
mbInformation, MB_OK);

WizardForm.ProgressGauge.Style := npbstNormal;
WizardForm.StatusLabel.Caption := '';
end;
end;

关于command-line - 如何在Inno Setup中执行cmd命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14984009/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com