3
votes

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.

1
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
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

1 Answers

7
votes

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;