Search code examples
inno-setupwindows-installer

Inno Setup AfterInstall procedure is executed too early, when installing MSI from Run section with /qn (silent) switch


After the execution of the mariadb-10.2.11-winx64.msi file, that installs the MariaDB 10.2.11 Server, I would like to make some changes on the my.ini file of the MariaDB 10.2.11 Server after it has been installed.

I have tried to use the AfterInstall parameter as shown bellow:


[Files]
Source: C:\Setup\Bin\mariadb-10.2.11-winx64.msi; DestDir: {tmp}; \
    Flags: ignoreversion promptifolder deleteafterinstall; Components: server

[Run]
Filename: {tmp}\mariadb-10.2.11-winx64.msi; Parameters: /qn; \
    WorkingDir: {tmp}; Flags: shellexec waituntilterminated; AfterInstall: ConfigMyIni
[Code]

procedure ConfigMyIni;
var
  MyIni : String;
begin
  MyIni := ExpandConstant('{pf}\MariaDB 10.2\data\my.ini');
  if FileExists(MyIni) then
    begin
      if IniKeyExists('mysqld', 'character-set-server', MyIni) then
        SetIniString('mysqld', 'character-set-server', 'uft8', MyIni)
      else
        SetIniString('mysqld', 'character-set-server', 'uft8', MyIni);

      if IniKeyExists('mysqld', 'collation-server', MyIni) then
        SetIniString('mysqld', 'collation-server', 'uft8_bin', MyIni)
      else
        SetIniString('mysqld', 'collation-server', 'uft8_bin', MyIni);

      if IniKeyExists('mysqld', 'lower-case-table-names', MyIni) then
        SetIniString('mysqld', 'lower-case-table-names', '1', MyIni)
      else
        SetIniString('mysqld', 'lower-case-table-names', '1', MyIni);
    end;
end;

I have stepped through the script code and I have found that the ConfigMyIni procedure is executed before the end of the execution of the mariadb-10.2.11-winx64.msi file. The my.ini file does not exist at that moment. How can I force the ConfigMyIni procedure to be executed only after the end of the execution of the mariadb-10.2.11-winx64.msi file?

I have already read the help of Inno Setup and have searched for any answer on Stack Overflow but have not found any clue that I could follow to solve my problem.

Could anyone give some help on this problem?


Solution

  • That is a consequence of the /qn switch. With the switch, the top-level msiexec process delegates installation to a hidden subprocess and terminates itself immediately.

    Consider using /qb or /qb! or similar, instead.

    See msiexec command-line options.