[英]How to execute cmd commands in Inno Setup
為了靜默安裝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', 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.