Search code examples
returnhidensis

NSIS How do I unhide a section when something returns a specific value?


I have an installer created using the HM NIS Edit. And I want to be able to unhide the section called VDF if my check finds out its not installed. And hide it when it's installed and also don't execute that embed installer.

I hope I made myself clear.

This is the function:

Function .onInit #Check's wether the installer is in your installation folder. onInit means that it checks for that even before the installer is initialized.
  ${If} ${FileExists} "$EXEDIR\VDF2012-17.0.22.8.Client.exe"
    MessageBox MB_OK "VDF found"

  ${Else}
    MessageBox MB_OK "The Visual DataFlex setup was not found in the installation folder. However the installation of $(^Name) will still continue."

  ${EndIf}

Solution

  • To hide a section you must change its name to a empty string.

    To check/uncheck a section you should use the helper macros in sections.nsh.

    !include sections.nsh
    
    Section "VDF" SID_VDF
    #Install VDF
    SectionEnd
    
    Function .onInit
    ${IfNot} ${FileExists} "$EXEDIR\VDF2012-17.0.22.8.Client.exe"
      !insertmacro UnselectSection ${SID_VDF}
      SectionSetText ${SID_VDF} ""
    ${EndIf}
    FunctionEnd
    

    To unhide you would give it a non-empty name but it is usually less work to show it by default and hide when required...