0

How to run a bat file in the Code section (procedure DeinitializeSetup)?

As I tried to do:

Exec('"' + installationFolder + '\mysql\db\db.cmd"',
     '"'+ installationFolder +'"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

Source and destination parameters are returning to the correct locations.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Rafael LGC
  • 127
  • 1
  • 2
  • 6
  • I'm not comfortable with [these](http://www.jrsoftware.org/ishelp/index.php?topic=scriptevents) commands, perhaps you'll have better luck. Otherwise, please include a more specific requirement to run, and/or what attempts you have made? – Bloodied Nov 10 '15 at 17:27
  • I need to run bat file in DeinitializeSetup to reconfigure and reinstall the Tomcat, Red5 and mySQL as service. These bat files will run if an error occurs or if the user cancels the installation, so the previous program is restored. – Rafael LGC Nov 10 '15 at 17:52
  • What do you mean by *"Source and destination parameters"*? – Martin Prikryl Nov 10 '15 at 18:41

1 Answers1

3

To execute the batch file, use Exec support function.

There should be no quotes in the Filename parameter of the Exec().

procedure DeinitializeSetup();
var
  InstallationFolder: string;
  ResultCode: Integer;
begin
  InstallationFolder := ExpandConstant('{app}');
  if Exec(InstallationFolder + '\mysql\db\test.bat',
          '"' + InstallationFolder + '"',
          '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
    Log('Succeeded running batch file');
  end
    else
  begin
    Log('Failed running batch file');
  end;
end;

If I install a test.bat with this contents:

@echo off
echo This is test
echo The provided installation path is %1
echo Without quotes: %~1
echo The current working directory is:
cd
pause

using:

[Files]
Source: "test.bat"; DestDir: "{app}\mysql\db"

I get this at the end of the installation:

Batch output

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992