23

I'm trying to create an installer using NSIS Modern User Interface for the first time. I would like to know how I can add an option (checkbox) for users to select to have a desktop shortcut created on the Finish Page (the last screen of the installer) in addition to the "Run XXXX" option that's already there.

1
  • 3
    Two pleas: (a) Don't check the "Put useless desktop icon" checkbox by default. The desktop is a far inferior program launching method in Vista and later compared to the search in the start menu. And (b) Make sure that the run checkbox causes the program to run not with adminsitrativ privileges but as the currently interactively logged-on user.
    – Joey
    Commented Oct 4, 2009 at 21:59

2 Answers 2

43

If you are not using readme checkbox on the finish page, you can use it to perform whatever action you want:

Function finishpageaction
CreateShortcut "$desktop\foo.lnk" "$instdir\foo.exe"
FunctionEnd

!define MUI_FINISHPAGE_SHOWREADME ""
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create Desktop Shortcut"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION finishpageaction
!insertmacro MUI_PAGE_FINISH
8
  • 2
    Shouldn't we use MUI_FINISHPAGE_RUN, MUI_FINISHPAGE_RUN_TEXT, MUI_FINISHPAGE_RUN_FUNCTION, MUI_PAGE_FINISH instead? What is the difference between these and MUI_FINISHPAGE_SHOWREADME, etc.? Commented Mar 15, 2012 at 13:33
  • @David There is no real difference other than the default text.
    – Anders
    Commented Mar 15, 2012 at 17:17
  • @Anders Can we add this code :- CreateShortCut "$DESKTOP\${MUI_PRODUCT}.lnk" "$INSTDIR\${MUI_FILE}.exe" "" in Function .onInstSuccess Commented Apr 11, 2019 at 19:54
  • @AnkeshkumarJaisansaria You can but if you are not giving the user a choice then you might as well do it in a Section.
    – Anders
    Commented Apr 11, 2019 at 22:58
  • How do you check whether the checkbox is checked or not? I want to use it to enable/disable telemetry...
    – tig
    Commented Mar 24, 2020 at 16:57
11

An alternate, and the simplest way to allow the user to add a desktop icon is to create a custom Section that does it. The user can then choose to add the shortcut in the "features" page of the installer and you don't have to do heavy modifications of the UI.

Section "Desktop Shortcut" SectionX
    SetShellVarContext current
    CreateShortCut "$DESKTOP\Your Program.lnk" "$INSTDIR\YourProgram.exe"
SectionEnd
2
  • As this puts the option in an unusual, unexpected and often simply skipped section of the installer, I would recommend against doing it like this. Asking whether the user wants a shortcut to be placed is expected to be at the end of the installation process, for whatever reason.
    – J. Stoever
    Commented Mar 6, 2011 at 16:36
  • Generally, it is expected at the end of the installation, because it is a minor detail that can be completely skipped. Desktop shortcuts are convenient, but not necessary. They are not required in order to install the application. Keeping these kinds of options at the end of the installation process helps make the user feel like more is getting done with less effort involved.
    – jay_t55
    Commented Jun 17, 2013 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.