NSIS(Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序。它提供了安装、卸载、系统设置、文件解压缩等功能。这如其名字所指出的那样,NSIS 是通过它的脚本语言来描述安装程序的行为和逻辑的。NSIS 的脚本语言和通常的编程语言有类似的结构和语法,但它是为安装程序这类应用所设计的。
https://nsis.sourceforge.io/Download
# 本地程序安装脚本
!define PRODUCT_NAME "BIIMS"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_WEB_SITE "https://soft.cdsy.xyz"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
SetCompressor /SOLID lzma
SetCompressorDictSize 32
; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"
; MUI
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
; ----- 当前文件同级下的exe.ico图标 -----
!define MUI_ICON "exe.ico"
!define MUI_UNICON "exe.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "welcome.jpg"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "welcome.jpg"
!define MUI_COMPONENTSPAGE_SMALLDESC
!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "鼠标移到组件上可查看相应说明"
; Welcome
!insertmacro MUI_PAGE_WELCOME
; 组件选择页面
!insertmacro MUI_PAGE_COMPONENTS
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 开始菜单设置页面
# var ICONS_GROUP
#!define MUI_STARTMENUPAGE_NODISABLE
#!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}"
#!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
#!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
#!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
#!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
#!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe"
#!define MUI_FINISHPAGE_RUN_NOTCHECKED ;默认不选中 '运行程序' 复选框
#!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Readme.txt"
#!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED ;默认不选中 '自述文件' 复选框
#!define MUI_FINISHPAGE_LINK "【某某某平台】"
#!define MUI_FINISHPAGE_LINK_LOCATION "${PRODUCT_WEB_SITE}"
#!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "English"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
-- 输入文件程序名 --
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails hide ;设置是否显示安装详细信息
ShowUnInstDetails hide
BrandingText "作者:路飞"
Section "!主程序" SEC01
SectionIn RO ;必选组件灰色
SetOutPath "$INSTDIR"
SetOverwrite on
File "Readme.txt"
File "TSCLIB.dll"
File "TSCLIB.lib"
File "biims.exe"
File /r "jre"
; 创建开始菜单快捷方式
; !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
; CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe"
; CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
; CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe"
; !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
; 安装.NET Framework
;Section "Microsoft .NET Framework 2.0" SEC02
; File "DotNet.exe"
; ExecWait '"DotNet.exe" /q:a /c:"install.exe /q"'
;SectionEnd
; Section -AdditionalIcons
; !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
; WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
; CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\项目主页.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
; CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk" "$INSTDIR\uninst.exe"
; !insertmacro MUI_STARTMENU_WRITE_END
; SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\${PRODUCT_NAME}.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}" "DisplayIcon" "$INSTDIR\${PRODUCT_NAME}.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
SectionEnd
# 写注册表,自定义网络协议
#Section -Post
# WriteRegStr HKCR "biims" "" "URL:AutoHotKey biims Protocol"
# WriteRegStr HKCR "biims" "URL Protocol" ""
# WriteRegStr HKCR "biims\DefaultIcon" "" "biims.exe,1"
# WriteRegStr HKCR "biims\shell\open\command" "" "$INSTDIR\biims.exe %1"
#SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Section "i5100-300打印机驱动" SEC02
SetOutPath "$INSTDIR"
SetOverwrite on
File /r "i5100"
SetOutPath "$INSTDIR\i5100\Installer"
ExecWait '"BradyInstallerSetup.exe" /q'
SetOutPath "$INSTDIR"
SectionEnd
#Section "BBP12打印机驱动" SEC03
# SetOutPath "$INSTDIR\"
# SetOverwrite on
# File /r "bbp12"
# SetOutPath "$INSTDIR\bbp12"
# ExecWait '"DriverWizard.exe" /q'
# SetOutPath "$INSTDIR"
#SectionEnd
; 区段组件描述
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC01} "必备组件"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "项目使用i5100-300打印机打印防冻标签,如果确认已经安装,则不必勾选。"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC03} "项目使用BBP12打印机打印普通标签,如果确认已经安装,则不必勾选。"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
/******************************
* 以下是安装程序的卸载部分 *
******************************/
Section Uninstall
; !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
Delete "$INSTDIR\uninst.exe"
; Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
; SetShellVarContext current ;当前用户开始菜单
; Delete "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk"
; Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk"
; Delete "$SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk"
; RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
; SetShellVarContext all ;全部用户开始菜单
; Delete "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk"
; Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk"
; Delete "$SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk"
; RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
RMDir /r "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
DeleteRegKey HKCR "biims"
SetAutoClose false
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
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
4.由于脚本自定义加载一些了文件,所以要将exe.ico、Readme.txt、welcome.jpg、TSCLIB.dll、TSCLIB.lib、jre文件目录、i5100驱动包、以及由launch4j生成的biims.exe程序复制到与biims.nsi脚本文件同级目录下,编译后会在当前文件下生成Setup.exe可运行的windows下的可执行的安装程序。