简体   繁体   English

如何在Inno Setup中执行cmd命令

[英]How to execute cmd commands in Inno Setup

For installing MySQL silently, I tried following command in cmd and it works fine: 为了静默安装MySQL,我尝试在cmd中执行以下命令,它工作正常:

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

But, how can I run that command Before Installing in Inno Setup ? 但是,如何在Inno Setup中安装之前运行该命令?

You can execute it by calling Exec function from the CurStepChanged event method, when the step will be ssInstall . 您可以通过从CurStepChanged事件方法调用Exec函数来执行它,此步骤将是ssInstall In the following script is shown, how to include that MySQL installer into your setup and how to extract and execute it right before the installation starts: 在下面的脚本中显示了如何将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;

Utilize the unused progress bar: 利用未使用的进度条:

Since it takes some time before the installation of MySQL finishes, and you've decided to hide the user interface of the installer (what might also be quite unsafe anyway), you can extend the script to use the progress bar which is shown at its starting position during the installation and which is unused that time. 由于MySQL的安装完成需要一些时间,并且您决定隐藏安装程序的用户界面(无论如何也可能是非常不安全的),您可以扩展脚本以使用其中显示的进度条。安装期间的起始位置,该时间未使用。 The following code switches (on at least Windows XP systems) the Inno Setup's installation progress bar to marquee style and shows a description in the status label. 以下代码将Inno Setup的安装进度条切换(至少在Windows XP系统上)到marquee style并在状态标签中显示说明。 When MySQL installation is done, the progress bar is switched back to the normal mode and the actual Inno Setup installation starts: 完成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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM