4

I have a working NSIS Modern UI 2 script that has five components. One of them is the main application, and there are four helper applications. Due to the nature of the applications, none of them requires the other to run; hence, they are all optional installs. This includes the main application.

At the finish page, I can have an option to start the main application with

!define MUI_FINISHPAGE_RUN "$INSTDIR\MyProgram.exe"
!define MUI_FINISHPAGE_RUN_TEXT "Start the main program"

as long as that goes before the

!insertmacro MUI_PAGE_FINISH

command. However, I don't want the checkbox to be visible (or at least enabled) if the user doesn't install the main application.

I've tried putting the first two lines inside the Section MainSection, but it doesn't show the box because by then, the UI has already been created.

I'd prefer not to always have it enabled and point to a function that runs if it's been installed, and shows a MessageBox otherwise.

Is there a way to do this?

4

1 回答 1

8

这些 MUI 定义在编译时使用,您需要在运行时修改复选框:

!include LogicLib.nsh
!include MUI2.nsh
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$instdir\Maybe.exe"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ModifyRunCheckbox
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English

Section "Maybe" SID_MAYBE
; File "Maybe.exe"
SectionEnd

Function ModifyRunCheckbox
${IfNot} ${SectionIsSelected} ${SID_MAYBE} ; You could also check if the file exists...
    SendMessage $mui.FinishPage.Run ${BM_SETCHECK} ${BST_UNCHECKED} 0
    EnableWindow $mui.FinishPage.Run 0 ; Or ShowWindow $mui.FinishPage.Run 0
${EndIf}
FunctionEnd
于 2012-12-02T14:14:43.810 回答