Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup: How to run a code procedure in Run section or before Run section?

Tags:

inno-setup

I want to remove the old database before installing the new one, to update it for the user.

I have the following scenario:

In my Components section I have an option for the user:

[Components]
Name: "updateDatabase";  Description: "Update Database";  Types: custom; \
    Flags: checkablealone disablenouninstallwarning

And I have in Code section, a procedure to execute, if the user selects this option, in the run section, before installing the new one.

[Code]
procedure RemoveOldDatabase();
begin
...
end;

[Run]
**--> Here I want to call RemoveOldDatabase if Components: updateDatabase is checked**
Filename: "database.exe"; StatusMsg: "Installing new database..."; Components: updateDatabase

The installation of the new database works fine. The problem is I want to remove the old one before installing the new one, calling the procedure RemoveOldDatabase.

Is it possible by only using Inno Setup?

Thanks.

like image 327
KurayamiArai Avatar asked Oct 15 '25 17:10

KurayamiArai


1 Answers

One way, in my view really simple and still descriptive, is to execute your procedure as a BeforeInstall parameter function of your [Run] section entry. A BeforeInstall parameter function is executed once right before an entry is processed (and only if it's processed, which in your case is when the component is selected). You would write just this:

[Run]
Filename: "database.exe"; Components: UpdateDatabase; BeforeInstall: RemoveOldDatabase

[Code]
procedure RemoveOldDatabase;
begin
  { ... }
end;
like image 124
TLama Avatar answered Oct 18 '25 06:10

TLama