; 注意 : 文件要保存为 UTF-8-BOM 编码 , 否则在执行此nsi脚本的时候会出现 Bad Text Encoding的错误
# 包含头文件
!include "MUI.nsh"
!include "LogicLib.nsh"
!define MUI_ABORTWARNING
!define MUI_ICON "./uires/logo.ico" #安装icon
!define MUI_UNICON "./uires/logo.ico" #卸载icon
!insertmacro MUI_PAGE_WELCOME #安装欢迎页面
!insertmacro MUI_PAGE_DIRECTORY #选择安装目录页面
!insertmacro MUI_LANGUAGE "SimpChinese" #安装界面显示的语言
!insertmacro MUI_PAGE_INSTFILES #安装过程页面
LangString ProductName ${LANG_SimpChinese} "PC客户端"
LangString UnInstallTip ${LANG_SimpChinese} "准备好卸载了吗" #卸载提示
LangString InstallTip ${LANG_SimpChinese} "准备好安装了吗" # 安装提示
LangString RunExeTip ${LANG_SimpChinese} "是否立即运行程序" # 运行程序提示
LangString FinishRunButtonText ${LANG_SimpChinese} "完成"
LangString FinishCheckBoxText ${LANG_SimpChinese} "myapp.exe"
LangString UninstallEnsure ${LANG_SimpChinese} "你确实要完全移除 $(ProductName) ,及其所有的组件?"
LangString UninstallResult ${LANG_SimpChinese} "$(ProductName) 已成功地从你的计算机移除。"
!define MUI_FINISHPAGE_TEXT $(RunExeTip)
!define MUI_FINISHPAGE_BUTTON $(FinishRunButtonText) #完成按钮的文案
!define MUI_FINISHPAGE_RUN_TEXT $(FinishCheckBoxText) #运行应用程序旁边的文字
!define MUI_FINISHPAGE_RUN "$INSTDIR\myapp.exe" #安装完成运行程序
!insertmacro MUI_PAGE_FINISH #安装完成页面 define定义的属性 要在对应的页面 insertmacro 之前
; 安装程序初始定义常量
!define PRODUCT_NAME $(ProductName)
!define PRODUCT_VERSION "1.0.0.1"
!define PRODUCT_PUBLISHER $(ProductName)
!define PRODUCT_WEB_SITE "http://www.baidu.com"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define REG_NAME "myapp1"
Name "myapp" #安装界面显示的名称
OutFile "${REG_NAME}Install.exe" #输出的安装包的名称路径
InstallDir "D:\${REG_NAME}Install" #安装界面的选择目录时的默认安装目录
; 安装section 打包的时候(makenisi)程序会执行的地方
Section Install
SetOutPath $INSTDIR
File /r .\setup\*.dll #将此目录下的所有dll 打包进安装包
File .\setup\myapp.exe
;协议注册启动程序
WriteRegStr HKCR "${REG_NAME}" "" ""
WriteRegStr HKCR "${REG_NAME}" "URL Protocol" ""
WriteRegStr HKCR "${REG_NAME}\DefaultIcon" "" "${REG_NAME}.exe,1"
WriteRegStr HKCR "${REG_NAME}\shell" "" ""
WriteRegStr HKCR "${REG_NAME}\shell\open" "" ""
WriteRegStr HKCR "${REG_NAME}\shell\open\command" "" '"$INSTDIR\myapp.exe" "%1"'
SectionEnd
; 卸载section 运行卸载程序会执行的地方
Section Uninstall
;MessageBox MB_ICONINFORMATION|MB_OK $(UnInstallTip)
DeleteRegKey HKCR "${REG_NAME}\shell\open\command"
DeleteRegKey HKCR "${REG_NAME}\shell\open"
DeleteRegKey HKCR "${REG_NAME}\shell"
DeleteRegKey HKCR "${REG_NAME}\DefaultIcon"
DeleteRegKey HKCR "${REG_NAME}"
Delete "$INSTDIR\*.dll"
Delete "$INSTDIR\myapp.exe"
Delete "$INSTDIR\uninst.exe"
;RMDir /r "$INSTDIR"
SectionEnd
;卸载程序的输出
Section -Post
WriteUninstaller ".\uninst.exe" #卸载程序 会在安装完成后写入到安装目录
SectionEnd
/* 普通函数 可以用Call 来调用 */
Function NormalFunc
MessageBox MB_ICONINFORMATION|MB_OK "normal func"
FunctionEnd
# 安装之前执行的回调函数
Function .onInit
MessageBox MB_ICONINFORMATION|MB_OK $(InstallTip)
Call NormalFunc
FunctionEnd
# 卸载之前执行的回调函数
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 $(UninstallEnsure) IDYES true IDNO false
true:
;检测进程是否运行
Goto done
false:
Abort
done:
Goto +1 ;Goto +1 goes to the next instruction, Goto -1 goes to the previous instruction, etc.
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK $(UninstallResult)
FunctionEnd