赞
踩
程序设计好以后会生成若干可执行文件和依赖文件。为了方便程序被更好地使用,需要将程序封装为一个安装程序。
Windows 安装 NSIS
下载地址:https://nsis.sourceforge.io/Download
NSIS(Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序,提供了安装、卸载、系统设置、文件解压缩等功能。NSIS通过脚本语言来描述安装程序的行为和逻辑的。
下载地址:https://sourceforge.net/projects/hmne/
HW VNISEDIT是他的这门语言的一个开发工具,能通过向导自动生成一些代码,下面我们做一个简单的应用程序打包步骤
打开 HM NIS Edit ,进入安装向导
选择 文件-> 新建脚本(向导)
Unicode true
可以使用notepad++,修改成bom的utf-8格式即可。
- ; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
-
- ; 安装程序初始定义常量
- !define PRODUCT_NAME "小v内网助手"
- !define PRODUCT_VERSION "1.0"
- !define PRODUCT_PUBLISHER "迈帮科技, Inc."
- !define PRODUCT_WEB_SITE "http://www.xiaovie.com"
- !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
- !define PRODUCT_UNINST_ROOT_KEY "HKLM"
-
- SetCompressor lzma
-
- ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
- !include "MUI.nsh"
-
- ; MUI 预定义常量
- !define MUI_ABORTWARNING
- !define MUI_ICON "setup.ico"
- !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
-
- ; 欢迎页面
- !insertmacro MUI_PAGE_WELCOME
- ; 许可协议页面
- !insertmacro MUI_PAGE_LICENSE "软件安装许可协议.rtf"
- ; 安装过程页面
- !insertmacro MUI_PAGE_INSTFILES
- ; 安装完成页面
- ;!define MUI_FINISHPAGE_RUN "$INSTDIR\install.bat"
- ;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\*.*"
- !insertmacro MUI_PAGE_FINISH
-
- ; 安装卸载过程页面
- !insertmacro MUI_UNPAGE_INSTFILES
-
- ; 安装界面包含的语言设置
- !insertmacro MUI_LANGUAGE "SimpChinese"
-
- ; 安装预释放文件
- !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
- ; ------ MUI 现代界面定义结束 ------
-
- Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
- OutFile "小v内网助手服务.exe"
- InstallDir "$PROGRAMFILES\xiaovie"
- InstallDirRegKey HKCU "Software\xiaovie natapp" ""
- ShowInstDetails show
- ShowUnInstDetails show
- BrandingText "小v内网助手"
-
- Section "主程序(必须)" SEC01
- SetOutPath "$INSTDIR"
- SetOverwrite ifnewer
- File /r "xiaovie_helper\*.*"
- ;CreateDirectory ""
- ;CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\natapp.exe"
- SectionEnd
-
- Section -AdditionalIcons
- WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
- CreateDirectory "$SMPROGRAMS\小v内网助手"
- CreateShortCut "$SMPROGRAMS\小v内网助手\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
- CreateShortCut "$SMPROGRAMS\小v内网助手\Uninstall.lnk" "$INSTDIR\uninst.exe"
- SectionEnd
-
- Section -Post
- WriteUninstaller "$INSTDIR\uninst.exe"
- WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
- WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
- WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
- WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
- WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
- WriteRegStr HKCU "Software\xiaovie natapp" "" $INSTDIR
- ExecWait 'nssm install XiaovieNatapp'
- Exec 'nssm start XiaovieNatapp'
- ExecWait 'nssm install XiaovieNginx'
- Exec 'nssm start XiaovieNginx'
- ;WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "natapp" "$INSTDIR\natapp.exe"
- ;WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "nginx" "$INSTDIR\nginx.exe"
- ;Exec "nginx.exe"
- SectionEnd
-
- /******************************
- * 以下是安装程序的卸载部分 *
- ******************************/
- Section Uninstall
- nsExec::Exec "taskkill /im nginx.exe /f"
- nsExec::Exec "taskkill /im natapp.exe /f"
-
- Exec 'sc stop XiaovieNginx'
- Exec 'sc delete XiaovieNginx'
- Exec 'sc stop XiaovieNatapp'
- Exec 'sc delete XiaovieNatapp'
-
- ;ExecWait 'nssm remove XiaovieNatapp'
- ;ExecWait 'nssm stop XiaovieNatapp'
-
- ;ExecWait 'nssm remove XiaovieNginx'
- ;ExecWait 'nssm stop XiaovieNginx'
-
- nsExec::Exec "taskkill /im nssm.exe /f"
-
- Delete "$INSTDIR\${PRODUCT_NAME}.url"
- Delete "$INSTDIR\uninst.exe"
- Delete "$INSTDIR\natapp.exe"
- Delete "$INSTDIR\nginx.exe"
- Delete "$INSTDIR\nssm.exe"
-
- Delete "$SMPROGRAMS\小v内网助手\Uninstall.lnk"
- Delete "$SMPROGRAMS\小v内网助手\Website.lnk"
- ;Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
-
- RMDir "$SMPROGRAMS\小v内网助手"
- RMDir ""
-
- RMDir /r "$INSTDIR\temp"
- RMDir /r "$INSTDIR\logs"
- RMDir /r "$INSTDIR\html"
- RMDir /r "$INSTDIR\docs"
- RMDir /r "$INSTDIR\contrib"
- RMDir /r "$INSTDIR\conf"
-
- RMDir "$INSTDIR"
-
- DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
- DeleteRegKey /ifempty HKCU "Software\xiaovie natapp"
- ;DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "natapp"
- ;DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "nginx"
- ;Exec 'sc stop XiaovieNginx'
- ;Exec 'sc delete XiaovieNginx'
- ;Exec 'sc stop XiaovieNatapp'
- ;Exec 'sc delete XiaovieNatapp'
- SetAutoClose true
- SectionEnd
-
- #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
-
- !include x64.nsh
- Function .onInit
- ${If} ${RunningX64}
- ${EnableX64FSRedirection}
- ${else}
- MessageBox MB_OK "对不起,该应用需要在64位操作系统中运行!"
- Abort
- ${EndIf}
- InitPluginsDir
- ;创建互斥防止重复运行
- System::Call 'kernel32::CreateMutexA(i 0, i 0, t "WinSnap_installer") i .r1 ?e'
- Pop $R0
- StrCmp $R0 0 +3
- MessageBox MB_OK|MB_ICONEXCLAMATION "有一个 小v内网助手 安装向导已经运行!"
- Abort
- FunctionEnd
-
- Section -
- Detailprint '$SYSDIR'
- DetailPrint '$WINDIR'
- DetailPrint '$PROGRAMFILES'
- SectionEnd
-
-
- Function un.onInit
- MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
- Abort
- FunctionEnd
-
- Function un.onUninstSuccess
- HideWindow
- MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
- FunctionEnd
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。