NSIS (Nullsoft Scriptable Install System)是一个开源的 Windows 系统下安装程序制作程序,它通过脚本语言来描述安装程序的行为和逻辑。

项目主页:http://nsis.sourceforge.net/
 
下面是一个基本的安装程序脚本模板(建议使用HM NIS Edit来编辑,编译):
!include "Library.nsh"

!define PRODUCT_NAME "XXX系统"
!define PRODUCT_VERSION "1.2.1"
!define PRODUCT_PUBLISHER "XX电子科技"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\YYYY.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

!include "MUI.nsh"

!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\win-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
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup\YYYY_Setup_${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES\YYYY"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  File "Bin\ef_simulate_client.py"
  File "Bin\ef_simulate_server.py"
  File "Bin\ef_display_client.py"
  File "Bin\YYYY.exe"
  File "Bin\YYYY.exe.config"
  File "Bin\SQLite.Interop.dll"
  
  SetOutPath "$INSTDIR\Audios"
  File /r "Bin\Audios\*.*"
  
  SetOutPath "$INSTDIR\Data"
  File /r "Bin\Data\*.*"
  
  SetOutPath "$INSTDIR\Icons"
  File /r "Bin\Icons\*.*"
  
  SetOutPath "$INSTDIR\Images"
  File /r "Bin\Images\*.*"
  
  CreateDirectory "$INSTDIR\Log"
  
  !insertmacro InstallLib REGDLL NOTSHARED NOREBOOT_NOTPROTECTED "Bin\zkemkeeper.dll" $INSTDIR\abcd.dll $INSTDIR
  
  SetShellVarContext all
  CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}${PRODUCT_VERSION}"
  CreateShortCut  "$SMPROGRAMS\${PRODUCT_NAME}${PRODUCT_VERSION}\${PRODUCT_NAME}${PRODUCT_VERSION}.lnk" "$INSTDIR\YYYY.exe"
  CreateShortCut     "$DESKTOP\${PRODUCT_NAME}${PRODUCT_VERSION}.lnk" "$INSTDIR\YYYY.exe"
SectionEnd

Section -AdditionalIcons
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}${PRODUCT_VERSION}\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\YYYY.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\YYYY.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd

Function un.onInit
  !insertmacro MUI_UNGETLANGUAGE
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  !insertmacro UninstallLib REGDLL NOTSHARED NOREBOOT_NOTPROTECTED $INSTDIR\zkemkeeper.dll

  SetShellVarContext current
  Delete "$DESKTOP\${PRODUCT_NAME}${PRODUCT_VERSION}.lnk"
  RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}${PRODUCT_VERSION}"
  
  SetShellVarContext all
  Delete "$DESKTOP\${PRODUCT_NAME}${PRODUCT_VERSION}.lnk"
  RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}${PRODUCT_VERSION}"
  
  RMDir /r "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

本文链接地址: NSIS 安装程序脚本模板
http://qingfengju.com/index.asp?id=378

分类:脚本编程 查看次数:7719 发布时间:2014-10-31 20:12:25