Archive: Changing behavior based on installed components


Changing behavior based on installed components
I have an application that has several components, one of which is an executable GUI. I'd like to give the user the option of launching that GUI (which is easy enough with MUI_FINISHPAGE_RUN), but only if they've actually chosen to install it.

Is there a way to disable the check box on the last page that gives the user the option to run the executable during runtime based on which components have been installed?


Use the custom function MUI_FINISHPAGE_RUN_FUNCTION as described in MUI docs.


Thanks for the input, I see the function but I can't find anywhere in the docs that explains how I would do either of the following:

1 - Hide the check box that gives the option to run the executable

2 - Determine which components were installed so I can decide whether or not to hide the check box

Any thoughts?


Well, the doc explains that this certain function could be used instead of the standard "run my application" behaviour.
Therefore you should add code into this function in order to determine which components were installed, so accordingly you may show or skip the checkbox.


Therefore you should add code into this function in order to determine which components were installed, so accordingly you may show or skip the checkbox.

Apologies if my question has been unclear, but I what I'm trying to figure out is HOW to do the two things mentioned here. I've read through the docs but I see no way of actually finding out what has been installed or how to mess with the check box.


Use

${If} ${SectionIsSelected} ${SectionId}
...
${EndIf}

where SectionId is defined with your Section:
Section "A section" SectionId


You need to !include LogicLib.nsh and also ensure that this code goes after your Section code in the script.

Just to show you how that code works behind the scenes which you could also use instead:

SectionGetFlags ${SectionId} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
StrCmp $R0 ${SF_SELECTED} [] []


Stu

If the issue is to hide the checkbox depending on a selected section, you don't even need the function MUI_FINISHPAGE_RUN_FUNCTION as I mentioned above.
The example below shows the checkbox when section 2 (additional) is selected.

OutFile "Test.exe"
InstallDir "$PROGRAMFILES\Test"
ShowInstDetails show

!include "mui.nsh"
!include "LogicLib.nsh"

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW func_show
!define MUI_FINISHPAGE_RUN myapp
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

Section "Main" sec1
SetOutPath "$INSTDIR"
Detailprint "Installing Section 1 (Main)"
sleep 3000
SectionEnd

Section /o "Additional" sec2
SetOutPath "$INSTDIR"
Detailprint "Installing Section 2 (Additional)"
sleep 3000
SectionEnd


Function func_show
${Unless} ${SectionIsSelected} ${sec2}
GetDlgItem $0 $MUI_HWND 1203
ShowWindow $0 ${SW_HIDE}
${EndUnless}
FunctionEnd

Thanks for all the help, those examples are quite educational got me going in the right direction. I ended up having to add one more line to uncheck the checkbox, otherwise it would still try to launch the executable since it was in a checked state even though it was hidden.

SendMessage $0 ${BM_SETCHECK} ${BST_UNCHECKED} 0

have a look at the CUIN source, it disables/hides components depending on a prior messagebox. should explain what you're looking for.