为了静默安装
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;