9

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 ?

Hamed Kamrava
  • 12,359
  • 34
  • 87
  • 125
  • I wouldn't personally use the `qn` option for this sort of installer. It may take some time (since it's a database system), and note that during the time the installation of MySQL will be in progress, user will see just "empty" overall installation progress bar without a notice that something happens on the background. – TLama Feb 20 '13 at 16:20
  • For user notice i'm using like this and user can see that. Do you have better manner? – Hamed Kamrava Feb 20 '13 at 16:39
  • I think it's fine, but where will you execute the `ECHO` command ? Do you have a batch file for this ? – TLama Feb 20 '13 at 17:03
  • Yes exactly i've a batch file.Can i use `Echo` in Inno Setup? – Hamed Kamrava Feb 20 '13 at 17:07
  • 1
    You can execute that batch file. It's about modifying code from my post. As another way that comes to my mind is to use the existing progress bar. When the MySQL installer would start, you'd switch the progress bar to [marquee style](http://i.msdn.microsoft.com/dynimg/IC510732.png) with the information text about the installation is in progress and when it finishes it will be switched back to a normal behavior (where the installer progress will take the control of it). – TLama Feb 20 '13 at 17:19
  • I've added script for utilization of the unused progress bar (switched to that marquee style). – TLama Feb 20 '13 at 17:51

1 Answers1

11

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 2
    This will work, but for preinstallation stuff it's now better to use the `PrepareToInstall` event function instead. This is better able to handle errors and other requirements such as reboot-before-continuing. See the example script included with Inno for more details. I would also strongly recommend using `/qb` instead of `/qn`; it still immediately starts the install but it shows progress while doing so. – Miral Feb 21 '13 at 20:03
  • @Miral, that's true, if reboot after install would be needed. About error handling; from `CurStepChanged` at `ssInstall` step you can still tell the user that installation of MySQL failed and `Abort` the setup if you follow this way. About the `qn` option; as I said, I'm against that as well. – TLama Feb 22 '13 at 02:11
  • 1
    I know, I was just trying to re-emphasise for the OP. :) – Miral Feb 22 '13 at 18:42
  • I tried to exec this too `"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqlinstanceconfig.exe" -i -q ServiceName=MySQL RootPassword=mysql ServerType=DEVELOPER DatabaseType=MYISAM Port=3306 Charset=utf8` But it does't work !! – Hamed Kamrava Feb 23 '13 at 16:15
  • Sorry, but *"doesn't work"* is the worst explanation you could use to describe, what's wrong with something what I can't see you to execute. Does the `Exec` function return True ? If so, what is the `ResultCode` it returns ? Anyway, using hardcoded paths is not a good idea... – TLama Feb 23 '13 at 16:22