1 NSIS版本为2.45的中文版本。 2 启动程序后界面显示为:
3 安装效果图:
下面是代码:
; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "ImageConvert"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "huangtao"
!define PRODUCT_WEB_SITE "http://blog.net/taoerit"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\setup.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 "C:\ImageCovert\Themes\application\application.ico" ;安装图标
!define MUI_UNICON "C:\ImageCovert\Themes\application\uninstall.ico" ;卸载图标
!define MUI_WELCOMEPAGE_TITLE " ${PRODUCT_NAME} ${PRODUCT_VERSION} 安装向导" ;标题名称
!define MUI_WELCOMEFINISHPAGE_BITMAP "C:\logo.bmp" ;欢迎向导左侧图标
!define MUI_WELCOMEPAGE_TEXT " ImageConvert是图片处理软件\r\n\r\n 软件作者:黄涛 \r\n\r\n 官方网址:http://blog.net/taoerit\r\n\r\n $_CLICK"
BrandingText "http://blog.net/taoerit"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\汉化说明.txt"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "汉化说明"
!AddPluginDir "C:\Program Files (x86)\NSIS\Plugins"
!AddIncludeDir "C:\Program Files (x86)\NSIS\Include"
ReserveFile "C:\Program Files (x86)\NSIS\Plugins\ButtonLinker.dll"
;!include MUI2.nsh
;!include ButtonLinkerLib.nsh
;!include UsefulLib.nsh
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 许可协议页面
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE "c:\ImageCovert\Licence.txt" ;许可协议说明
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\setup.exe" ;程序执行 exe
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese" ;安装语言
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ;
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "ImageConvert.exe" ;生成压缩可执行文件
InstallDir "$PROGRAMFILES\ImageConvert"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show
Section "ImageConvert" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "C:\ImageCovert\setup.exe"
CreateDirectory "$SMPROGRAMS\ImageConvert" ;创建开始菜单程序目录
CreateShortCut "$SMPROGRAMS\ImageConvert\ImageConvert.lnk" "$INSTDIR\setup.exe" ; 创建程序的链接
CreateShortCut "$DESKTOP\ImageConvert.lnk" "$INSTDIR\setup.exe" ;创建桌面快捷方式
File /r "C:\ImageCovert\*.*"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\ImageConvert\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\ImageConvert\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\setup.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\setup.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\setup.exe"
Delete "$INSTDIR\*"
RMDir /r "$INSTDIR"
Delete "$SMPROGRAMS\ImageConvert\Uninstall.lnk"
Delete "$SMPROGRAMS\ImageConvert\Website.lnk"
Delete "$DESKTOP\ImageConvert.lnk"
Delete "$SMPROGRAMS\ImageConvert\ImageConvert.lnk"
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "C:\programdata\Microsoft\Windows\Start Menu\Programs\ImageConvert\*"
RMDIR "C:\programdata\Microsoft\Windows\Start Menu\Programs\ImageConvert"
RMDir /r "$INSTDIR\Themes"
RMDir /r "$INSTDIR\Plugins"
RMDir /r "$INSTDIR\Language"
Delete "$SMPROGRAMS\ImageConvert\*"
RMDir /r "$SMPROGRAMS\ImageConvert"
;DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function onGUIInit
BrandingURL::Set /NOUNLOAD "200" "0" "0" "http://blog.net/taoerit"
FunctionEnd
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