Search code examples
inno-setupsuppress

How to properly close out of Inno Setup wizard without prompt?


Part of my installer checks for a latest version on our server and downloads automatically if necessary, just after the welcome page. The actual check and download are in a function CheckForNewInstaller which returns True if new installer was downloaded and has executed, and False if it needs to continue. If the new installer was downloaded (True) then the wizard needs to shut down.

Using the following code, I have done this using WizardForm.Close. However, it still prompts the user if they're sure they wish to cancel. In normal scenarios, I still want the user to get this prompt if they attempt to close the installer. However, I need to suppress this dialog when I need to forcefully close the wizard. I also cannot be terminating the process, because the cleanup process wouldn't happen properly.

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ResultCode: Integer;
  X: Integer;
begin
  Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  Result := True;
  case CurPageID of
    wpWelcome: begin
      if CheckForNewInstaller then begin
        //Need to close this installer as new one is starting
        WizardForm.Close;
      end;
    end;
    ....
  end;
end;

How can I close this installer completely down without any further user interaction?


Solution

  • This can be done by handling the CancelButtonClick event and setting the Confirm parameter...

    var
      ForceClose: Boolean;
    
    procedure Exterminate;
    begin
      ForceClose:= True;
      WizardForm.Close;  
    end;
    
    procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
    begin
      Confirm:= not ForceClose;
    end;
    
    function NextButtonClick(CurPageID: Integer): Boolean;
    var
      ResultCode: Integer;
      X: Integer;
    begin
      Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
      Result := True;
      case CurPageID of
        wpWelcome: begin
          if CheckForNewInstaller then begin
            Exterminate;
          end;
        end;
        ....
      end;
    end;