4

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
KurayamiArai
  • 311
  • 1
  • 4
  • 11
  • If you're going to just delete file(s) or directory(ies), use the `[InstallDelete]` section rather than procedure. It will perform deletion of your choice as the very first thing in the installation process. – TLama Oct 08 '14 at 13:19
  • The problem is I have to remove more than files of directorys. I have to remove the old database program itself, calling windows commands. My code section works fine if I call it in the NextButtonClick procedure, by example, but I'm a little lost to know how to call it before the run section. – KurayamiArai Oct 08 '14 at 13:25

1 Answers1

9

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
TLama
  • 75,147
  • 17
  • 214
  • 392
  • Thank you. I knew about the BeforeInstall parameter but not that I could call a procedure in there. Thanks. – KurayamiArai Oct 08 '14 at 15:25
  • You're welcome! Well, those parameters exist just for this purpose. – TLama Oct 08 '14 at 16:18
  • It is quite surprising, but although the help for `[Run] Section` ([link](http://www.jrsoftware.org/ishelp/index.php?topic=runsection)) does *not* specify `BeforeInstall` and `AfterInstall` as valid options, *both* are working well within this section. – itsho May 02 '18 at 14:23
  • @itsho I think it's because they aren't specific to `[Run]`. Per the BeforeInstall link, "There are two optional parameters that are supported by all sections whose entries are separated into parameters except for [Languages], [Types], [Components] and [Tasks]" – RiverHeart Jun 19 '23 at 13:46