Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute cmd commands in Inno Setup

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

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

like image 551
Hamed Kamrava Avatar asked Feb 20 '13 15:02

Hamed Kamrava


People also ask

How do I run a program from CMD EXE?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How do I make an inno file executable?

Go to Menu, Project, then Compile to compile and create the setup file. This will create a complete installer. Run the Setup and your application will be installed correctly. Innosetup offers an awesome alternative to create great looking Installers for free.

How do I run a command file?

You can run the commands stored in a CMD file in Windows by double-clicking the file or executing it in the Command Prompt (CMD. EXE) utility.


1 Answers

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:

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;
like image 158
TLama Avatar answered Sep 19 '22 11:09

TLama