Skip to content
⌘ NSIS Forum Archive

Conditionally present Quick Launch checkbox

9 posts

pauljlucas#

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.
Anders#
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
pauljlucas#
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.)
Anders#
section "name" id
...
UnselectSection ${id}

also, to _hide_ the item, you need to set its name to an empty string
pauljlucas#
The:

UnselectSection ${S_QuickLaunch}
by itself made no difference.

How do you set its name to an empty string?
pauljlucas#
I now have:

Function .onInit
${If} ${IsWin7}
UnselectSection ${S_QuickLaunch}
SectionSetText ${S_QuickLaunch} ""
${EndIf}
FunctionEnd
and there's still no change.
Anders#

!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
pauljlucas#
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.