加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

命令行 – 如何在Inno Setup中执行cmd命令

发布时间:2020-12-15 04:03:55 所属栏目:大数据 来源:网络整理
导读:为了静默安装 MySQL,我尝试在cmd中执行以下命令,它工作正常: msiexec /i "mysql-essential-6.0.11-alpha-winx64.msi" /qn 但是,如何在Inno Setup中安装之前运行该命令? 解决方法 您可以通过从 CurStepChanged 事件方法调用 Exec 函数来执行它,此步骤将是ss
为了静默安装 MySQL,我尝试在cmd中执行以下命令,它工作正常:
msiexec /i "mysql-essential-6.0.11-alpha-winx64.msi" /qn

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

解决方法

您可以通过从 CurStepChanged事件方法调用 Exec函数来执行它,此步骤将是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的安装完成需要一些时间,并且您决定隐藏安装程序的用户界面(无论如何也可能是非常不安全的),您可以扩展脚本以使用其中显示的进度条.安装期间的起始位置,该时间未使用.以下代码将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',MB_OK);

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读