Archive: Simple example to conditionally create a shortcut?


Simple example to conditionally create a shortcut?
I have an optional section and a "Create shortcuts" section. I would like to create a shortcut for the files installed in the optional section only if it was selected to install. I know this is simple, but I've searched and I can't find a simple example that shows how to do this, and I'm not familiar enough with the scripting language to figure it out. Can someone post an example to fill in the blanks?

Section "Optional"
File "opt.exe"
; What do I add to create some global variable?
SectionEnd

Section "Shortcuts"
CreateDirectory "$SMPROGRAMS\Ex"
CreateShortCut "$SMPROGRAMS\Ex\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "" 0
; Now what do I add to conditionally create this shortcut?
CreatShortCut "$SMPROGRMAMS\Ex\Opt.lnk" "$INSTDIR\opt.exe" "" "" 0
SectionEnd

!include "Sections.nsh"

Section "Optional" SecOptional
File "opt.exe"
SectionEnd

Section "Shortcuts"

CreateDirectory "$SMPROGRAMS\Ex"
CreateShortcut "$SMPROGRAMS\Ex\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "" 0

SectionGetFlags ${SecOptional} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
StrCmp $R0 ${SF_SELECTED} "" +2
CreateShortcut "$SMPROGRMAMS\Ex\Opt.lnk" "$INSTDIR\opt.exe" "" "" 0

SectionEnd

Works great. I'm using the ModernUI, and to include sections.nsh I had to comment out the

!define HWND_BROADCAST 0xFFFF

line, as the installer gave an error ("HWND_BROADCAST" already defined!).


Joost fixed that, thanks.