当前位置:   article > 正文

NSIS打包exe样例脚本_hm vnisedit 最新版

hm vnisedit 最新版

1、前言

程序设计好以后会生成若干可执行文件和依赖文件。为了方便程序被更好地使用,需要将程序封装为一个安装程序。

2、平台和环境

Windows 安装 NSIS

下载地址:https://nsis.sourceforge.io/Download

NSIS(Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序,提供了安装、卸载、系统设置、文件解压缩等功能。NSIS通过脚本语言来描述安装程序的行为和逻辑的。

安装HW VNIS Edit

下载地址:https://sourceforge.net/projects/hmne/

HW VNISEDIT是他的这门语言的一个开发工具,能通过向导自动生成一些代码,下面我们做一个简单的应用程序打包步骤

3、使用教程

打开 HM NIS Edit ,进入安装向导

 

选择 文件-> 新建脚本(向导)

 NSIS打包exe样例脚本


 

解决中文乱码,可以再脚本开头加一行代码

Unicode true

 

解决协议乱码

可以使用notepad++,修改成bom的utf-8格式即可。 

 

包含卸载,服务注册,卸载结束程序

  1. ; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
  2. ; 安装程序初始定义常量
  3. !define PRODUCT_NAME "小v内网助手"
  4. !define PRODUCT_VERSION "1.0"
  5. !define PRODUCT_PUBLISHER "迈帮科技, Inc."
  6. !define PRODUCT_WEB_SITE "http://www.xiaovie.com"
  7. !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  8. !define PRODUCT_UNINST_ROOT_KEY "HKLM"
  9. SetCompressor lzma
  10. ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
  11. !include "MUI.nsh"
  12. ; MUI 预定义常量
  13. !define MUI_ABORTWARNING
  14. !define MUI_ICON "setup.ico"
  15. !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
  16. ; 欢迎页面
  17. !insertmacro MUI_PAGE_WELCOME
  18. ; 许可协议页面
  19. !insertmacro MUI_PAGE_LICENSE "软件安装许可协议.rtf"
  20. ; 安装过程页面
  21. !insertmacro MUI_PAGE_INSTFILES
  22. ; 安装完成页面
  23. ;!define MUI_FINISHPAGE_RUN "$INSTDIR\install.bat"
  24. ;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\*.*"
  25. !insertmacro MUI_PAGE_FINISH
  26. ; 安装卸载过程页面
  27. !insertmacro MUI_UNPAGE_INSTFILES
  28. ; 安装界面包含的语言设置
  29. !insertmacro MUI_LANGUAGE "SimpChinese"
  30. ; 安装预释放文件
  31. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  32. ; ------ MUI 现代界面定义结束 ------
  33. Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  34. OutFile "小v内网助手服务.exe"
  35. InstallDir "$PROGRAMFILES\xiaovie"
  36. InstallDirRegKey HKCU "Software\xiaovie natapp" ""
  37. ShowInstDetails show
  38. ShowUnInstDetails show
  39. BrandingText "小v内网助手"
  40. Section "主程序(必须)" SEC01
  41. SetOutPath "$INSTDIR"
  42. SetOverwrite ifnewer
  43. File /r "xiaovie_helper\*.*"
  44. ;CreateDirectory ""
  45. ;CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\natapp.exe"
  46. SectionEnd
  47. Section -AdditionalIcons
  48. WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  49. CreateDirectory "$SMPROGRAMS\小v内网助手"
  50. CreateShortCut "$SMPROGRAMS\小v内网助手\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  51. CreateShortCut "$SMPROGRAMS\小v内网助手\Uninstall.lnk" "$INSTDIR\uninst.exe"
  52. SectionEnd
  53. Section -Post
  54. WriteUninstaller "$INSTDIR\uninst.exe"
  55. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  56. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  57. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  58. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  59. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
  60. WriteRegStr HKCU "Software\xiaovie natapp" "" $INSTDIR
  61. ExecWait 'nssm install XiaovieNatapp'
  62. Exec 'nssm start XiaovieNatapp'
  63. ExecWait 'nssm install XiaovieNginx'
  64. Exec 'nssm start XiaovieNginx'
  65. ;WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "natapp" "$INSTDIR\natapp.exe"
  66. ;WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "nginx" "$INSTDIR\nginx.exe"
  67. ;Exec "nginx.exe"
  68. SectionEnd
  69. /******************************
  70. * 以下是安装程序的卸载部分 *
  71. ******************************/
  72. Section Uninstall
  73. nsExec::Exec "taskkill /im nginx.exe /f"
  74. nsExec::Exec "taskkill /im natapp.exe /f"
  75. Exec 'sc stop XiaovieNginx'
  76. Exec 'sc delete XiaovieNginx'
  77. Exec 'sc stop XiaovieNatapp'
  78. Exec 'sc delete XiaovieNatapp'
  79. ;ExecWait 'nssm remove XiaovieNatapp'
  80. ;ExecWait 'nssm stop XiaovieNatapp'
  81. ;ExecWait 'nssm remove XiaovieNginx'
  82. ;ExecWait 'nssm stop XiaovieNginx'
  83. nsExec::Exec "taskkill /im nssm.exe /f"
  84. Delete "$INSTDIR\${PRODUCT_NAME}.url"
  85. Delete "$INSTDIR\uninst.exe"
  86. Delete "$INSTDIR\natapp.exe"
  87. Delete "$INSTDIR\nginx.exe"
  88. Delete "$INSTDIR\nssm.exe"
  89. Delete "$SMPROGRAMS\小v内网助手\Uninstall.lnk"
  90. Delete "$SMPROGRAMS\小v内网助手\Website.lnk"
  91. ;Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
  92. RMDir "$SMPROGRAMS\小v内网助手"
  93. RMDir ""
  94. RMDir /r "$INSTDIR\temp"
  95. RMDir /r "$INSTDIR\logs"
  96. RMDir /r "$INSTDIR\html"
  97. RMDir /r "$INSTDIR\docs"
  98. RMDir /r "$INSTDIR\contrib"
  99. RMDir /r "$INSTDIR\conf"
  100. RMDir "$INSTDIR"
  101. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  102. DeleteRegKey /ifempty HKCU "Software\xiaovie natapp"
  103. ;DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "natapp"
  104. ;DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "nginx"
  105. ;Exec 'sc stop XiaovieNginx'
  106. ;Exec 'sc delete XiaovieNginx'
  107. ;Exec 'sc stop XiaovieNatapp'
  108. ;Exec 'sc delete XiaovieNatapp'
  109. SetAutoClose true
  110. SectionEnd
  111. #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
  112. !include x64.nsh
  113. Function .onInit
  114. ${If} ${RunningX64}
  115. ${EnableX64FSRedirection}
  116. ${else}
  117. MessageBox MB_OK "对不起,该应用需要在64位操作系统中运行!"
  118. Abort
  119. ${EndIf}
  120. InitPluginsDir
  121. ;创建互斥防止重复运行
  122. System::Call 'kernel32::CreateMutexA(i 0, i 0, t "WinSnap_installer") i .r1 ?e'
  123. Pop $R0
  124. StrCmp $R0 0 +3
  125. MessageBox MB_OK|MB_ICONEXCLAMATION "有一个 小v内网助手 安装向导已经运行!"
  126. Abort
  127. FunctionEnd
  128. Section -
  129. Detailprint '$SYSDIR'
  130. DetailPrint '$WINDIR'
  131. DetailPrint '$PROGRAMFILES'
  132. SectionEnd
  133. Function un.onInit
  134. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
  135. Abort
  136. FunctionEnd
  137. Function un.onUninstSuccess
  138. HideWindow
  139. MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
  140. FunctionEnd

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/496729
推荐阅读
  

闽ICP备14008679号