Archive: Conditionally present Quick Launch checkbox


Conditionally present Quick Launch checkbox
Since Quick Launch icons apparently aren't used in Windows 7, I want my installer not to present the user with the Quick Launch checkbox on the Components page if the user is running Windows 7.

First, to determine whether the user is running Windows 7, I have:


Function .onInit
Var /GLOBAL WindowsVersion
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
StrCpy $R1 $R0 3
StrCmp $R1 '6.1' 0 +2
StrCpy $WindowsVersion "7"
FunctionEnd


I'm using MUI2 and also have:


!define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_COMPONENTS

; ... [snip] ...

LangString LS_QuickLaunchIconSecName ${LANG_ENGLISH} \
"Quick Launch icon"

; ... [snip] ...

Section "$(LS_QuickLaunchIconSecName)"
CreateShortCut "$QUICKLAUNCH\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe"
SectionEnd


However, it's not clear how to conditionally disable the Quick Launch checkbox (yet still leave the remaining components intact).

Also, as an aside, I wrote this stuff a while ago. In looking back, it's no longer clear to me how NSIS "knows" the above section is the section that specifies the Quick Launch checkbox. So, how does it "know?"

Thanks for any help.

don't read the registry to find the windows version, use winver.nsh

to disable/uncheck a section, the section needs an id, specify the id like so: section "display name" myId

then, somewhere _after_ that section in the script, you need to use a function that is called at runtime (.oninit,.onguiinit or the pre callback for the components page) and disable the section if needed using the helper macros in sections.nsh


OK, I now have:


Section "$(LS_QuickLaunchIconSecName)" S_QuickLaunch
CreateShortCut "$QUICKLAUNCH\${APP_NAME}.lnk" "$INSTDIR\${APP_NAME}.exe"
SectionEnd

; ... [snip] ...

Function .onInit
${If} ${IsWin7}
UnselectSection S_QuickLaunch
${Endif}
FunctionEnd

When I run this on a machine running Windows 7, it still shows the Quick Launch checkbox. (Yes, I'm including the necessary files.)

section "name" id
...
UnselectSection ${id}

also, to _hide_ the item, you need to set its name to an empty string


The:


UnselectSection ${S_QuickLaunch}

by itself made no difference.

How do you set its name to an empty string?

by reading about sections in the helpfile


I now have:


Function .onInit
${If} ${IsWin7}
UnselectSection ${S_QuickLaunch}
SectionSetText ${S_QuickLaunch} ""
${EndIf}
FunctionEnd

and there's still no change.


!include WinVer.nsh
!include Sections.nsh
page components
page instfiles
Section foo bar
SectionEnd

Function .onInit
${If} 1 == 1 ;replace with OS test
!insertmacro UnselectSection ${bar}
SectionSetText ${bar} ""
${EndIf}
FunctionEnd

D'oh! I realized I wasn't editing the copy of the file that was being used to generate the installer, so of course the result was no different. :(

Anyway, it works now that I'm editing the correct file. Thanks for your patience.