NSIS入门程序实例,麻雀虽小,五脏俱全

时间:2022-03-26 18:47:51

;全局宏定义
!define PRODUCT_NAME            "TS-8300 Dispacher"
!define PRODUCT_VERSION         "V4.00.01"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_UNINST_KEY      "Software/Microsoft/Windows/CurrentVersion/Uninstall/${PRODUCT_NAME} ${PRODUCT_VERSION}"
!define PRODUCT_MAINAPP         "LotusInstall.log"

outfile "setup.exe"
name    ${PRODUCT_NAME}

loadlanguagefile "${NSISDIR}/Contrib/Language files/SIMPCHINESE.nlf"
brandingtext     "HYT Corpration"
icon             "${NSISDIR}/Contrib/Graphics/Icons/win-install.ico"
UninstallIcon    "${NSISDIR}/Contrib/Graphics/Icons/win-uninstall.ico"
installdir       "$PROGRAMFILES/${PRODUCT_NAME}"
licensedata      "license.rtf"
LicenseBkColor   000000
InstallColors    FFFFFF 000000
ShowInstDetails  show
XPStyle on

;界面定制
page license
page directory
page instfiles

UninstPage uninstConfirm
UninstPage instfiles

section "main"
  setoverwrite on
  setoutpath "$INSTDIR"

  file "LotusInstall.log"
sectionend

section "-post"
  ;生成卸载程序
  WriteUninstaller "uninstaller.exe"
  ;系统安装卸载程序中注册,绿色版不需要此部分
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR/uninstaller.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"     "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  ;安装桌面与开始菜单快捷方式
  CreateShortCut  "$DESKTOP/TS-8300 Dispacher.lnk"    "$INSTDIR/${PRODUCT_MAINAPP}"
  CreateShortCut  "$SMPROGRAMS/TS-8300 Dispacher.lnk" "$INSTDIR/${PRODUCT_MAINAPP}"
sectionend

section "Uninstall"
  RMDir /r "$INSTDIR"
sectionend

section "-un.post"
  ;系统安装卸载程序中反注册,绿色版不需要此部分
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  ;卸载桌面与开始菜单快捷方式
  Delete "$DESKTOP/TS-8300 Dispacher.lnk"
  Delete "$SMPROGRAMS/TS-8300 Dispacher.lnk"
sectionend