NSIS - 仅在安装时运行程序

wch*_*gin 4 installer nsis

我有一个工作的NSIS Modern UI 2脚本,它有五个组件.其中一个是主要应用程序,有四个帮助应用程序.由于应用程序的性质,它们都不需要另一个运行; 因此,它们都是可选安装.这包括主要应用程序.

在完成页面,我可以选择启动主应用程序

!define MUI_FINISHPAGE_RUN "$INSTDIR\MyProgram.exe"
!define MUI_FINISHPAGE_RUN_TEXT "Start the main program"
Run Code Online (Sandbox Code Playgroud)

只要在此之前

!insertmacro MUI_PAGE_FINISH
Run Code Online (Sandbox Code Playgroud)

命令.但是,如果用户没有安装主应用程序,我不希望该复选框可见(或至少启用).

我已经尝试将前两行放入其中Section MainSection,但它没有显示该框,因为到那时,UI已经被创建了.

我不希望总是启用它并指向一个在安装后运行的函数,并显示MessageBox其他情况.

有没有办法做到这一点?

And*_*ers 6

那些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
Run Code Online (Sandbox Code Playgroud)