; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "TRU Mate"
!define PRODUCT_VERSION "1.1"
!define PRODUCT_PUBLISHER "杰为软件系统(深圳)有限公司"
!define PRODUCT_WEB_SITE "http://www.jwis.cn"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\mateAutoUpdate.exe"
!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 "20160711035221213_easyicon_net_48.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 语言选择窗口常量设置
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\mateAutoUpdate.exe"
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\TRU Mate"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show
BrandingText " "
Section "TRUMate" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "C:\Users\Administrator\Desktop\TRUIProcess1\mateAutoUpdate.exe"
CreateDirectory "$SMPROGRAMS\TRU Mate"
CreateShortCut "$SMPROGRAMS\TRU Mate\TRU Mate.lnk" "$INSTDIR\mateAutoUpdate.exe"
CreateShortCut "$DESKTOP\TRU Mate.lnk" "$INSTDIR\mateAutoUpdate.exe"
File /r "C:\Users\Administrator\Desktop\TRUIProcess1\*.*"
Call CheckVCRedist
Pop $R0
StrCmp $R0 "-1" 0 +3
ExecWait "$INSTDIR\vcredist_x86.exe /q" ;若不存在,执行静默安装
ExecWait "$INSTDIR\vcredist_x64.exe /q" ;若不存在,执行静默安装
SectionEnd
;添加admin权限
Section
WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\mateAutoUpdate.exe" "RUNASADMIN"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\TRU Mate\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\TRU Mate\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\mateAutoUpdate.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\mateAutoUpdate.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}"
SectionEnd
/******************************
* 以下是安装程序的卸载部分 *
******************************/
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\mateAutoUpdate.exe"
Delete "$SMPROGRAMS\TRU Mate\Uninstall.lnk"
Delete "$SMPROGRAMS\TRU Mate\Website.lnk"
Delete "$DESKTOP\TRU Mate.lnk"
Delete "$SMPROGRAMS\TRU Mate\TRU Mate.lnk"
RMDir "$SMPROGRAMS\TRU Mate"
RMDir /r "$INSTDIR\TRU_modules"
RMDir /r "$INSTDIR\resources"
RMDir /r "$INSTDIR\node_modules"
RMDir /r "$INSTDIR\locales"
RMDir /r "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function CheckVCRedist
Push $R0
ClearErrors
ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}" "Version"
; if VS 2005+ redist SP1 not installed, install it
IfErrors 0 VSRedistInstalled
StrCpy $R0 "-1"
VSRedistInstalled:
Exch $R0
FunctionEnd
Function .onInit
Push ""
Push ${LANG_ENGLISH}
Push English
Push ${LANG_SIMPCHINESE}
Push "中文(简体)"
Push A ; A means auto count languages
; for the auto count to work the first empty push (Push "") must remain
LangDLL::LangDialog "选择安装语言" "选择在安装期间使用的安装语言"
Pop $LANGUAGE
StrCmp $LANGUAGE "cancel" 0 +2
Abort
Push $R0
;ReadRegStr $R1 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
;StrCmp $R1 "" NO_Install YES_Install
;YES_Install:
CheckProc:
Push "mate.exe"
ProcessWork::existsprocess
Pop $R0
IntCmp $R0 0 Done
MessageBox MB_OKCANCEL|MB_ICONSTOP "安装程序检测到 ${PRODUCT_NAME} 正在运行。$\r$\n$\r$\n点击 “确定” 强制关闭${PRODUCT_NAME},继续安装。$\r$\n点击 “取消” 退出安装程序。" IDCANCEL Exit
Push "mate.exe"
Processwork::KillProcess
Sleep 1000
Goto CheckProc
Exit:
Abort
Done:
;SetDetailsPrint textonly
;DetailPrint "卸载旧版..."
;SetDetailsPrint listonly
;静默卸载旧版本并等待它完成后才继续,_?=是指定一个路径。
;ExecWait '"$INSTDIR\uninst.exe" /S _?=$INSTDIR'
;Delete "$INSTDIR\uninst.exe"
;Delete "$SMPROGRAMS\TRU Mate\Uninstall.lnk"
;Delete "$SMPROGRAMS\TRU Mate\Website.lnk"
;Delete "$DESKTOP\TRU Mate.lnk"
;Delete "$SMPROGRAMS\TRU Mate\TRU Mate.lnk"
;RMDir /r "$INSTDIR"
;DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
;DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
;Abort
;NO_Install:
Pop $R0
Push $R0
ClearErrors
ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}" "Version"
; 检测含有vc的注册表信息是否存在
IfErrors 0 VSRedistInstalled
Exec "$INSTDIR\vcredist_x86.exe /q" ;若不存在,执行静默安装
Exec "$INSTDIR\vcredist_x64.exe /q" ;若不存在,执行静默安装
StrCpy $R0 "-1"
; MessageBox MB_OK $R0
VSRedistInstalled:
; MessageBox MB_OK "已安装"
Exch $R0
FunctionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FindProcDLL::FindProc "mate.exe"
Pop $R0
IntCmp $R0 1 0 no_run
MessageBox MB_ICONSTOP "卸载程序检测到 ${PRODUCT_NAME} 正在运行,请关闭之后再卸载!"
Quit
no_run:
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd
; 安装程序初始定义常量
!define PRODUCT_NAME "TRU Mate"
!define PRODUCT_VERSION "1.1"
!define PRODUCT_PUBLISHER "杰为软件系统(深圳)有限公司"
!define PRODUCT_WEB_SITE "http://www.jwis.cn"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\mateAutoUpdate.exe"
!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 "20160711035221213_easyicon_net_48.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 语言选择窗口常量设置
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\mateAutoUpdate.exe"
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\TRU Mate"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show
BrandingText " "
Section "TRUMate" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "C:\Users\Administrator\Desktop\TRUIProcess1\mateAutoUpdate.exe"
CreateDirectory "$SMPROGRAMS\TRU Mate"
CreateShortCut "$SMPROGRAMS\TRU Mate\TRU Mate.lnk" "$INSTDIR\mateAutoUpdate.exe"
CreateShortCut "$DESKTOP\TRU Mate.lnk" "$INSTDIR\mateAutoUpdate.exe"
File /r "C:\Users\Administrator\Desktop\TRUIProcess1\*.*"
Call CheckVCRedist
Pop $R0
StrCmp $R0 "-1" 0 +3
ExecWait "$INSTDIR\vcredist_x86.exe /q" ;若不存在,执行静默安装
ExecWait "$INSTDIR\vcredist_x64.exe /q" ;若不存在,执行静默安装
SectionEnd
;添加admin权限
Section
WriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\mateAutoUpdate.exe" "RUNASADMIN"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\TRU Mate\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\TRU Mate\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\mateAutoUpdate.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\mateAutoUpdate.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}"
SectionEnd
/******************************
* 以下是安装程序的卸载部分 *
******************************/
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\mateAutoUpdate.exe"
Delete "$SMPROGRAMS\TRU Mate\Uninstall.lnk"
Delete "$SMPROGRAMS\TRU Mate\Website.lnk"
Delete "$DESKTOP\TRU Mate.lnk"
Delete "$SMPROGRAMS\TRU Mate\TRU Mate.lnk"
RMDir "$SMPROGRAMS\TRU Mate"
RMDir /r "$INSTDIR\TRU_modules"
RMDir /r "$INSTDIR\resources"
RMDir /r "$INSTDIR\node_modules"
RMDir /r "$INSTDIR\locales"
RMDir /r "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function CheckVCRedist
Push $R0
ClearErrors
ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}" "Version"
; if VS 2005+ redist SP1 not installed, install it
IfErrors 0 VSRedistInstalled
StrCpy $R0 "-1"
VSRedistInstalled:
Exch $R0
FunctionEnd
Function .onInit
Push ""
Push ${LANG_ENGLISH}
Push English
Push ${LANG_SIMPCHINESE}
Push "中文(简体)"
Push A ; A means auto count languages
; for the auto count to work the first empty push (Push "") must remain
LangDLL::LangDialog "选择安装语言" "选择在安装期间使用的安装语言"
Pop $LANGUAGE
StrCmp $LANGUAGE "cancel" 0 +2
Abort
Push $R0
;ReadRegStr $R1 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
;StrCmp $R1 "" NO_Install YES_Install
;YES_Install:
CheckProc:
Push "mate.exe"
ProcessWork::existsprocess
Pop $R0
IntCmp $R0 0 Done
MessageBox MB_OKCANCEL|MB_ICONSTOP "安装程序检测到 ${PRODUCT_NAME} 正在运行。$\r$\n$\r$\n点击 “确定” 强制关闭${PRODUCT_NAME},继续安装。$\r$\n点击 “取消” 退出安装程序。" IDCANCEL Exit
Push "mate.exe"
Processwork::KillProcess
Sleep 1000
Goto CheckProc
Exit:
Abort
Done:
;SetDetailsPrint textonly
;DetailPrint "卸载旧版..."
;SetDetailsPrint listonly
;静默卸载旧版本并等待它完成后才继续,_?=是指定一个路径。
;ExecWait '"$INSTDIR\uninst.exe" /S _?=$INSTDIR'
;Delete "$INSTDIR\uninst.exe"
;Delete "$SMPROGRAMS\TRU Mate\Uninstall.lnk"
;Delete "$SMPROGRAMS\TRU Mate\Website.lnk"
;Delete "$DESKTOP\TRU Mate.lnk"
;Delete "$SMPROGRAMS\TRU Mate\TRU Mate.lnk"
;RMDir /r "$INSTDIR"
;DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
;DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
;Abort
;NO_Install:
Pop $R0
Push $R0
ClearErrors
ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}" "Version"
; 检测含有vc的注册表信息是否存在
IfErrors 0 VSRedistInstalled
Exec "$INSTDIR\vcredist_x86.exe /q" ;若不存在,执行静默安装
Exec "$INSTDIR\vcredist_x64.exe /q" ;若不存在,执行静默安装
StrCpy $R0 "-1"
; MessageBox MB_OK $R0
VSRedistInstalled:
; MessageBox MB_OK "已安装"
Exch $R0
FunctionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FindProcDLL::FindProc "mate.exe"
Pop $R0
IntCmp $R0 1 0 no_run
MessageBox MB_ICONSTOP "卸载程序检测到 ${PRODUCT_NAME} 正在运行,请关闭之后再卸载!"
Quit
no_run:
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd