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.
How to Add a Desktop Shortcut Option on Finish Page in NSIS installer?
Asked Answered
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. –
Powell
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
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.? –
Protective
@David There is no real difference other than the default text. –
Claro
@Claro Can we add this code :- CreateShortCut "$DESKTOP\${MUI_PRODUCT}.lnk" "$INSTDIR\${MUI_FILE}.exe" "" in Function .onInstSuccess –
Jeraldjeraldine
@AnkeshkumarJaisansaria You can but if you are not giving the user a choice then you might as well do it in a
Section
. –
Claro How do you check whether the checkbox is checked or not? I want to use it to enable/disable telemetry... –
Telepathy
@Telepathy the function is not executed if the checkbox is unchecked. You can inspect the state in the page leave callback function. –
Claro
The NSIS scripts compiler is very sensitive to the order in which things are placed in the script. The code which Anders has shown us must be placed before the !insertmacro MUI_PAGE_FINISH statement or you get the error: NSIS install function not referenced - zeroing code. You may not even know you have the error because the installer runs, it's just that the finish page does not have the shortcut option.. –
Spectacled
@DavidCasper Per-page settings need to be defined before the insertmacro for the specific page. The function can be anywhere. The MUI documentation tells you which defines are global and which are per-page. –
Claro
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
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. –
Hippocras
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. –
Toughen
© 2022 - 2024 — McMap. All rights reserved.