Inside Man
Inside Man

Reputation: 4372

Handling and customizing errors and messages in Inno Setup

Inno Setup will show different message boxes to the user. For example,

  1. When it tries to install a file that is in use, it will show a message to abort/ignore/cancel.

  2. When the setup is installing the files and the target path will have low space while installing, the setup will give an error.

I need to customize these message boxes on my own. (I do not want these native messages to be shown to the user) for example, I need to show another message box, or even totally do not show a specific message from Inno Setup, or changing a label when that message is going to fire.

Upvotes: 1

Views: 1753

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202118

All Inno Setup messages can be customized using the [Messages] section.

Some examples:


As for the change of the message box layout/design. You cannot really change it. With some fancy implementation of Check and BeforeInstall parameters, you might be able to catch some problems before Inno Setup detects them and handle them your custom way. But that's lot of work with unreliable results.

If you tell us what are you trying to achieve more specifically, you may get more specific answer.


If you need a solution that allows everything that Inno Setup allows on error, including clean abort of the installation, Check or BeforeInstall won't help as they do not have a way to cleanly abort it.

You would have to do all the checks before the installation, e.g. in CurStepChanged(ssInstall).

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: ShouldInstallFile

[Code]

var
  DontInstallFile: Boolean;

function ShouldInstallFile: Boolean;
begin
  Result := not DontInstallFile;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  FileName: string;
  Msg: string;
  Response: Integer;
begin
  if CurStep = ssInstall then
  begin
    FileName := ExpandConstant('{app}\MyProg.exe');
    repeat
      if FileExists(FileName) and (not DeleteFile(FileName)) then
      begin
        Msg := Format('File %s cannot be replaced', [FileName]);
        Response := MsgBox(Msg, mbError, MB_ABORTRETRYIGNORE)
        case Response of
          IDABORT: Abort;
          IDIGNORE: DontInstallFile := True;
        end;
      end;
    until (Response <> IDRETRY);
  end;
end;

Upvotes: 1

Related Questions