如何在Inno Setup中执行cmd命令 [英] How to execute cmd commands in Inno Setup

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

问题描述

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

For installing MySQL silently, I tried following command in cmd and it works fine:

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

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

But, how can I run that command Before Installing in Inno Setup ?

推荐答案

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

You can execute it by calling Exec function from the CurStepChanged event method, when the step will be 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:

#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:

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

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. 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. When MySQL installation is done, the progress bar is switched back to the normal mode and the actual Inno Setup installation starts:

#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;

这篇关于如何在Inno Setup中执行cmd命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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