Inno Setup: How to abort/terminate setup during install?

后端 未结 4 580
眼角桃花
眼角桃花 2020-12-01 12:19

During my install, I run a bat file. If the bat file returns an error, I need to abort/terminate the setup. I\'d like for it to do a MsgBox telling the user wha

4条回答
  •  感情败类
    2020-12-01 13:01

    Thank you, Robert. It is a common problem happening any time when script detects that setup cannot be continued. However, there is a problem in your solution. WizardForm.Close invokes cancel dialog, and installation is stopped only if user answers "Yes". To exit definitely, we should invoke CancelButtonClick.

    [Files]
    Source: "MYPROG.EXE"; DestDir: "{app}"; AfterInstall: MyAfterInstall
    
    [Code]
    var CancelWithoutPrompt: boolean;
    
    function InitializeSetup(): Boolean;
    begin
      CancelWithoutPrompt := false;
      result := true;
    end;
    
    procedure MyAfterInstall();
    begin
      { Do something }
      if BadResult then begin
        MsgBox('Should cancel because...',mbError,MB_OK)
        CancelWithoutPrompt := true;
        WizardForm.Close;
      end;
    end;
    
    procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
    begin
      if CurPageID=wpInstalling then
        Confirm := not CancelWithoutPrompt;
    end;
    

提交回复
热议问题