patlimosnero
patlimosnero

Reputation: 973

Undo or Rollback Installation

I want to perform rollback in IS when my AfterInstall function fails. Here is a sample of my Code.

[Files]
   Source: "MyWinService.exe"; DestDir: "{app}"; Flags: ignoreversion; AfterInstall:     MyAfterInstall
   Source: "MyApp.exe"; DestDir: "{app}"; Flags: ignoreversion
[Code]
   const
    WM_CLOSE = $0010;
   procedure MyAfterInstall();
   var
     exitCode: Integer;
   begin
      MsgBox (ExpandConstant('{cm:ErrServiceInstall}'), mbError, MB_OK);
      SendMessage(WizardForm.Handle, WM_CLOSE, 0, 0);
   end;

In this sample, I just directly want to cancel installation so to test rollback of installation. What happens here is that after MsgBox is displayed, ExitSetupMsgBox is displayed due to the SendMessage. When I click Yes in ExitSetupMsgBox, rollback will be performed. What I want is that ExitSetupMsgBox not displayed since I have already the MsgBox displayed. So when I clicked OK in MsgBox rollback will be performed.

Can this be done?

Upvotes: 1

Views: 1199

Answers (1)

Robert Love
Robert Love

Reputation: 12581

You could use the Event CancelButtonClick where you can turn of of the confirmation dialog.

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  Cancel := True;
  Confirm := False;
end;

You can trigger the cancel method by just closing the WizardForm, no need to send a special message just call. WizardForm.Close This is the only method I know of to cancel the install during an AfterInstall Event.

Note: This will not work if you have

[setup]
AllowCancelDuringInstall=no

or run your setup with the /NOCANCEL command line option.

Upvotes: 1

Related Questions