NSIS 设置桌面图标、开始菜单图标和 Abort/Retry/Ignore 错误
NSIS setup desktop icon, start menu icon and Abort/Retry/Ignore Error
我最近制作了一个 PyQt5 应用程序,并使用 pyinstaller 构建了它。我已经制作了 zip 文件。现在我想使用 NSIS 来获取安装程序。我转到示例页面并复制了以下代码 "Simple installer and uninstaller with start menu item" https://nsis.sourceforge.io/Simple_tutorials#Simple_installer_and_uninstaller_with_start_menu_item.
我试图阅读文档,但我对安装目录是什么感到困惑,是安装程序文件所在的位置还是在程序文件中 windows 上安装某些软件后的位置。所有安装文件都在C:/Program Files/[Some Software]中可见。是那个文件夹吗?还有 SetOutPath。我也想要类似的行为,即安装程序应该在桌面和开始菜单上有快捷方式图标的复选框。当用户 运行s 安装程序时,它应该指向 C:\Program Files[应用程序名称]。当前,当 运行 和 "a.nsi" 时,它给我 Retry/Ignore/ Abort 错误,带有复制代码的脚本。否则,当我尝试使用带有 zip 文件选项的 make installer 时,我得到了很好的安装程序,但它没有放置桌面图标或开始菜单图标,它显示的默认安装目录是桌面。
Name "Mailer"
# define name of installer
OutFile "Mailer-install.exe"
# For removing Start Menu shortcut in Windows 7
RequestExecutionLevel user
# define installation directory
InstallDir $PROGRAMFILES
# start default section
Section
# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
File "Mailer.zip"
# create the uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
# create a shortcut named "new shortcut" in the start menu programs directory
# point the new shortcut at the program uninstaller
CreateShortCut "$SMPROGRAMS\new shortcut.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
# uninstaller section start
Section "uninstall"
# first, delete the uninstaller
Delete "$INSTDIR\uninstall.exe"
# second, remove the link from the start menu
Delete "$SMPROGRAMS\new shortcut.lnk"
# uninstaller section end
SectionEnd
<h3> The logs if required</h3>
MakeNSIS v3.05 - Copyright 1999-2019 Contributors
See the file COPYING for license details.
Credits can be found in the Users Manual.
Processing config: C:\Program Files (x86)\NSIS\nsisconf.nsh
Processing default plugins: "C:\Program Files (x86)\NSIS\Plugins\x86-ansi\*.dll"
+ Banner::destroy
+ Banner::getWindow
+ Banner::show
+ BgImage::AddImage
+ BgImage::AddText
+ BgImage::Clear
+ BgImage::Destroy
+ BgImage::Redraw
+ BgImage::SetBg
+ BgImage::SetReturn
+ BgImage::Sound
+ Dialer::AttemptConnect
+ Dialer::AutodialHangup
+ Dialer::AutodialOnline
+ Dialer::AutodialUnattended
+ Dialer::GetConnectedState
+ InstallOptions::dialog
+ InstallOptions::initDialog
+ InstallOptions::show
+ LangDLL::LangDialog
+ Math::Script
+ StartMenu::Init
+ StartMenu::Select
+ StartMenu::Show
+ System::Alloc
+ System::Call
+ System::Copy
+ System::Free
+ System::Get
+ System::Int64Op
+ System::Store
+ System::StrAlloc
+ TypeLib::GetLibVersion
+ TypeLib::Register
+ TypeLib::UnRegister
+ UserInfo::GetAccountType
+ UserInfo::GetName
+ UserInfo::GetOriginalAccountType
+ VPatch::GetFileCRC32
+ VPatch::GetFileMD5
+ VPatch::vpatchfile
+ advsplash::show
+ nsDialogs::Create
+ nsDialogs::CreateControl
+ nsDialogs::CreateItem
+ nsDialogs::CreateTimer
+ nsDialogs::GetUserData
+ nsDialogs::KillTimer
+ nsDialogs::OnBack
+ nsDialogs::OnChange
+ nsDialogs::OnClick
+ nsDialogs::OnNotify
+ nsDialogs::SelectFileDialog
+ nsDialogs::SelectFolderDialog
+ nsDialogs::SetRTL
+ nsDialogs::SetUserData
+ nsDialogs::Show
+ nsExec::Exec
+ nsExec::ExecToLog
+ nsExec::ExecToStack
+ nsisdl::download
+ nsisdl::download_quiet
+ splash::show
!define: "MUI_INSERT_NSISCONF"=""
Changing directory to: "C:\Users\Dell\Desktop\New folder (3)\f"
Processing script file: "C:\Users\Dell\Desktop\New folder (3)\f\a.nsi" (ACP)
Name: "Mailer"
OutFile: "Mailer-install.exe"
InstallDir: "$PROGRAMFILES"
Section: ""
SetOutPath: "$INSTDIR"
File: "Mailer.zip" [compress] 57197161/57534535 bytes
WriteUninstaller: "$INSTDIR\uninstall.exe"
CreateShortcut: "$SMPROGRAMS\new shortcut.lnk"->"$INSTDIR\uninstall.exe" icon:,0, nwd=0, showmode=0x0, hotkey=0x0, comment=
SectionEnd
Section: "uninstall"
Delete: "$INSTDIR\uninstall.exe"
Delete: "$SMPROGRAMS\new shortcut.lnk"
SectionEnd
Processed 1 file, writing output (x86-ansi):
warning 7998: ANSI targets are deprecated
Processing pages... Done!
Removing unused resources... Done!
Generating language tables... Done!
Generating uninstaller... Done!
Output: "C:\Users\Dell\Desktop\New folder (3)\f\Mailer-install.exe"
Install: 1 page (64 bytes), 1 section (2072 bytes), 5 instructions (140 bytes), 40 strings (726 bytes), 1 language table (198 bytes).
Uninstall: 1 page (128 bytes), 1 section (2072 bytes), 3 instructions (84 bytes), 39 strings (617 bytes), 1 language table (194 bytes).
Using zlib compression.
EXE header size: 36352 / 37888 bytes
Install code: 728 / 2568 bytes
Install data: 57197165 / 57534547 bytes
Uninstall code+data: 909 / 1409 bytes
CRC (0x02F0CF53): 4 / 4 bytes
Total size: 57235158 / 57576416 bytes (99.4%)
1 warning:
7998: ANSI targets are deprecated
您在示例脚本中进行了致命更改,您将 InstallDir
更改为 $PROGRAMFILES
,如果您不是提升权限的管理员,则无法写入 $PROGRAMFILES
!
要让用户选择是否创建快捷方式,请将其放在单独的 Section
中并添加一个组件页面:
Name "MyApp"
OutFile "MyAppSetup.exe"
Unicode True
RequestExecutionLevel Admin ; Request UAC elevation
InstallDir "$ProgramFiles$(^Name)"
Page Components
Page Directory
Page InstFiles
Uninstpage UninstConfirm
Uninstpage InstFiles
!include LogicLib.nsh
!macro EnsureAdminRights
UserInfo::GetAccountType
Pop [=10=]
${If} [=10=] != "admin" ; Require admin rights on WinNT4+
MessageBox MB_IconStop "Administrator rights required!"
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
!macroend
Function .onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Function un.onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Section "Program files (Required)"
SectionIn Ro
SetOutPath $InstDir ; Sets the output directory for File instructions
WriteUninstaller "$InstDir\Uninst.exe"
File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install
SectionEnd
Section "Start Menu shortcut"
CreateShortcut /NoWorkingDir "$SMPrograms$(^Name).lnk" "$InstDir\MyApp.exe"
SectionEnd
Section -Uninstall
Delete "$InstDir\MyApp.exe"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
Delete "$SMPrograms$(^Name).lnk"
SectionEnd
注意:这是 install-shared.nsi example script 的略微修改版本。该脚本还向 Control Panel/Settings 应用程序注册了卸载程序,您也应该在真正的安装程序中这样做。
我最近制作了一个 PyQt5 应用程序,并使用 pyinstaller 构建了它。我已经制作了 zip 文件。现在我想使用 NSIS 来获取安装程序。我转到示例页面并复制了以下代码 "Simple installer and uninstaller with start menu item" https://nsis.sourceforge.io/Simple_tutorials#Simple_installer_and_uninstaller_with_start_menu_item.
我试图阅读文档,但我对安装目录是什么感到困惑,是安装程序文件所在的位置还是在程序文件中 windows 上安装某些软件后的位置。所有安装文件都在C:/Program Files/[Some Software]中可见。是那个文件夹吗?还有 SetOutPath。我也想要类似的行为,即安装程序应该在桌面和开始菜单上有快捷方式图标的复选框。当用户 运行s 安装程序时,它应该指向 C:\Program Files[应用程序名称]。当前,当 运行 和 "a.nsi" 时,它给我 Retry/Ignore/ Abort 错误,带有复制代码的脚本。否则,当我尝试使用带有 zip 文件选项的 make installer 时,我得到了很好的安装程序,但它没有放置桌面图标或开始菜单图标,它显示的默认安装目录是桌面。
Name "Mailer"
# define name of installer
OutFile "Mailer-install.exe"
# For removing Start Menu shortcut in Windows 7
RequestExecutionLevel user
# define installation directory
InstallDir $PROGRAMFILES
# start default section
Section
# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
File "Mailer.zip"
# create the uninstaller
WriteUninstaller "$INSTDIR\uninstall.exe"
# create a shortcut named "new shortcut" in the start menu programs directory
# point the new shortcut at the program uninstaller
CreateShortCut "$SMPROGRAMS\new shortcut.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
# uninstaller section start
Section "uninstall"
# first, delete the uninstaller
Delete "$INSTDIR\uninstall.exe"
# second, remove the link from the start menu
Delete "$SMPROGRAMS\new shortcut.lnk"
# uninstaller section end
SectionEnd
<h3> The logs if required</h3>
MakeNSIS v3.05 - Copyright 1999-2019 Contributors
See the file COPYING for license details.
Credits can be found in the Users Manual.
Processing config: C:\Program Files (x86)\NSIS\nsisconf.nsh
Processing default plugins: "C:\Program Files (x86)\NSIS\Plugins\x86-ansi\*.dll"
+ Banner::destroy
+ Banner::getWindow
+ Banner::show
+ BgImage::AddImage
+ BgImage::AddText
+ BgImage::Clear
+ BgImage::Destroy
+ BgImage::Redraw
+ BgImage::SetBg
+ BgImage::SetReturn
+ BgImage::Sound
+ Dialer::AttemptConnect
+ Dialer::AutodialHangup
+ Dialer::AutodialOnline
+ Dialer::AutodialUnattended
+ Dialer::GetConnectedState
+ InstallOptions::dialog
+ InstallOptions::initDialog
+ InstallOptions::show
+ LangDLL::LangDialog
+ Math::Script
+ StartMenu::Init
+ StartMenu::Select
+ StartMenu::Show
+ System::Alloc
+ System::Call
+ System::Copy
+ System::Free
+ System::Get
+ System::Int64Op
+ System::Store
+ System::StrAlloc
+ TypeLib::GetLibVersion
+ TypeLib::Register
+ TypeLib::UnRegister
+ UserInfo::GetAccountType
+ UserInfo::GetName
+ UserInfo::GetOriginalAccountType
+ VPatch::GetFileCRC32
+ VPatch::GetFileMD5
+ VPatch::vpatchfile
+ advsplash::show
+ nsDialogs::Create
+ nsDialogs::CreateControl
+ nsDialogs::CreateItem
+ nsDialogs::CreateTimer
+ nsDialogs::GetUserData
+ nsDialogs::KillTimer
+ nsDialogs::OnBack
+ nsDialogs::OnChange
+ nsDialogs::OnClick
+ nsDialogs::OnNotify
+ nsDialogs::SelectFileDialog
+ nsDialogs::SelectFolderDialog
+ nsDialogs::SetRTL
+ nsDialogs::SetUserData
+ nsDialogs::Show
+ nsExec::Exec
+ nsExec::ExecToLog
+ nsExec::ExecToStack
+ nsisdl::download
+ nsisdl::download_quiet
+ splash::show
!define: "MUI_INSERT_NSISCONF"=""
Changing directory to: "C:\Users\Dell\Desktop\New folder (3)\f"
Processing script file: "C:\Users\Dell\Desktop\New folder (3)\f\a.nsi" (ACP)
Name: "Mailer"
OutFile: "Mailer-install.exe"
InstallDir: "$PROGRAMFILES"
Section: ""
SetOutPath: "$INSTDIR"
File: "Mailer.zip" [compress] 57197161/57534535 bytes
WriteUninstaller: "$INSTDIR\uninstall.exe"
CreateShortcut: "$SMPROGRAMS\new shortcut.lnk"->"$INSTDIR\uninstall.exe" icon:,0, nwd=0, showmode=0x0, hotkey=0x0, comment=
SectionEnd
Section: "uninstall"
Delete: "$INSTDIR\uninstall.exe"
Delete: "$SMPROGRAMS\new shortcut.lnk"
SectionEnd
Processed 1 file, writing output (x86-ansi):
warning 7998: ANSI targets are deprecated
Processing pages... Done!
Removing unused resources... Done!
Generating language tables... Done!
Generating uninstaller... Done!
Output: "C:\Users\Dell\Desktop\New folder (3)\f\Mailer-install.exe"
Install: 1 page (64 bytes), 1 section (2072 bytes), 5 instructions (140 bytes), 40 strings (726 bytes), 1 language table (198 bytes).
Uninstall: 1 page (128 bytes), 1 section (2072 bytes), 3 instructions (84 bytes), 39 strings (617 bytes), 1 language table (194 bytes).
Using zlib compression.
EXE header size: 36352 / 37888 bytes
Install code: 728 / 2568 bytes
Install data: 57197165 / 57534547 bytes
Uninstall code+data: 909 / 1409 bytes
CRC (0x02F0CF53): 4 / 4 bytes
Total size: 57235158 / 57576416 bytes (99.4%)
1 warning:
7998: ANSI targets are deprecated
您在示例脚本中进行了致命更改,您将 InstallDir
更改为 $PROGRAMFILES
,如果您不是提升权限的管理员,则无法写入 $PROGRAMFILES
!
要让用户选择是否创建快捷方式,请将其放在单独的 Section
中并添加一个组件页面:
Name "MyApp"
OutFile "MyAppSetup.exe"
Unicode True
RequestExecutionLevel Admin ; Request UAC elevation
InstallDir "$ProgramFiles$(^Name)"
Page Components
Page Directory
Page InstFiles
Uninstpage UninstConfirm
Uninstpage InstFiles
!include LogicLib.nsh
!macro EnsureAdminRights
UserInfo::GetAccountType
Pop [=10=]
${If} [=10=] != "admin" ; Require admin rights on WinNT4+
MessageBox MB_IconStop "Administrator rights required!"
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED
Quit
${EndIf}
!macroend
Function .onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Function un.onInit
SetShellVarContext All
!insertmacro EnsureAdminRights
FunctionEnd
Section "Program files (Required)"
SectionIn Ro
SetOutPath $InstDir ; Sets the output directory for File instructions
WriteUninstaller "$InstDir\Uninst.exe"
File "/oname=$InstDir\MyApp.exe" "${NSISDIR}\Bin\MakeLangId.exe" ; Pretend that we have a real application to install
SectionEnd
Section "Start Menu shortcut"
CreateShortcut /NoWorkingDir "$SMPrograms$(^Name).lnk" "$InstDir\MyApp.exe"
SectionEnd
Section -Uninstall
Delete "$InstDir\MyApp.exe"
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
Delete "$SMPrograms$(^Name).lnk"
SectionEnd
注意:这是 install-shared.nsi example script 的略微修改版本。该脚本还向 Control Panel/Settings 应用程序注册了卸载程序,您也应该在真正的安装程序中这样做。