Search code examples
installationnsismessageboxmodern-ui

How to cancel a NSIS setup without showing a confirmation message box?


Having a NSIS setup with Modern UI 2, the user gets a message box to confirm when he clicks on the Cancel button in the installation wizard.

I want the user to be able to exit the installation wizard without confirming an additional "Are you sure?" dialog message box.

In the MUI sources I found this fragment:

!macro MUI_FUNCTION_ABORTWARNING

  Function .onUserAbort

    !ifdef MUI_PAGE_FUNCTION_ABORTWARNING
      Call ${MUI_PAGE_FUNCTION_ABORTWARNING}
    !endif

    !ifdef MUI_ABORTWARNING
      !insertmacro MUI_ABORTWARNING
    !endif

    !ifdef MUI_CUSTOMFUNCTION_ABORT
      Call "${MUI_CUSTOMFUNCTION_ABORT}"
    !endif
  FunctionEnd

!macroend

I am both able to define the MUI_PAGE_FUNCTION_ABORTWARNING function and the MUI_CUSTOMFUNCTION_ABORT function.

Since the actual message box is defined in the middle call to the MUI_ABORTWARNING macro, I see no way to stop the macro from being called.

My question is:

Is there a way to hinder MUI from showing the user a confirmation message box when he clicks the Cancel button during the setup process?


Solution

  • This warning is controlled by !define MUI_ABORTWARNING (Before you include mui.nsh):

    Name "Test"
    Outfile "Test.exe"
    RequestExecutionLevel user
    
    #Comment/uncomment this to toggle the messagebox: !define MUI_ABORTWARNING
    
    !include MUI2.nsh
    
    !insertmacro MUI_PAGE_WELCOME
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_PAGE_FINISH
    !insertmacro MUI_LANGUAGE English
    
    Section
    SectionEnd