如何在Inno Setup中执行cmd命令

时间:2013-02-20 15:44:50

标签: command-line inno-setup

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

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

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

1 个答案:

答案 0 :(得分:11)

当步骤为ssInstall时,您可以通过Exec事件方法调用CurStepChanged函数来执行此操作。在下面的脚本中显示了如何将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安装完成需要一些时间,并且您决定隐藏安装程序的用户界面(无论如何也可能非常不安全),您可以扩展脚本以使用进度条,即在安装期间显示在其起始位置,并且该时间未使用。以下代码将Inno Setup的安装进度条切换(至少在Windows XP系统上)到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;