windows 如何在 NSIS 安装程序的完成页面上添加桌面快捷方式选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1517471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:47:49  来源:igfitidea点击:

How to Add a Desktop Shortcut Option on Finish Page in NSIS installer?

windowsinstallernsis

提问by takoloco

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.

我第一次尝试使用 NSIS 现代用户界面创建安装程序。我想知道除了已经存在的“运行 XXXX”选项之外,如何添加一个选项(复选框)供用户选择在完成页面(安装程序的最后一个屏幕)上创建桌面快捷方式。

回答by Anders

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

回答by Julien Lebosquain

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.

允许用户添加桌面图标的另一种且最简单的方法是创建一个自定义部分来执行此操作。然后用户可以选择在安装程序的“功能”页面中添加快捷方式,而您不必对 UI 进行大量修改。

Section "Desktop Shortcut" SectionX
    SetShellVarContext current
    CreateShortCut "$DESKTOP\Your Program.lnk" "$INSTDIR\YourProgram.exe"
SectionEnd