功能强大的打包工具和NSIS Script Editor
NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers

NSIS 下载地址

HM NIS Edit 下载地址 or BridleNSIS for Visual Studio Code

#在设置找到此项
Nsisi:Path to makensis
D:\Program Files (x86)\NSIS\makensisw.exe

此功能包含

  • 欢迎界面
  • 注册协议界面
  • 组件界面
  • 安装目录界面
  • 完成界面
  • 卸载界面

支持

  • 压缩比最优化
  • 批量文件夹
  • 启动外部三方程序
  • 安装完成后启动程序
  • 卸载面板显示安装空间大小
  • 卸载
  • 检测系统位数
  • 支持重复安装提示
  • 附加图标

不支持

说明

脚本文件使用的是编码格式是 UTF-8 with BOM
拖动脚本到 makensisw.exe 自动编译
脚本源码部分来源于website
makensisw 文件下载

脚本源码

; Script generated by the HM NIS Edit Script Wizard.

;--------------------------------
; Style
  Unicode true
  ManifestDPIAware true
  XPStyle on
  ; RequestExecutionLevel admin
;--------------------------------
; MUI 1.67 compatible

  !include "MUI2.nsh"
  !include "FileFunc.nsh"
  !include "x64.nsh"

;--------------------------------
; Best Compression

  SetCompress Auto
  SetCompressor /SOLID lzma
  SetCompressorDictSize 64
  SetDatablockOptimize On

;--------------------------------
; Variables

  Var StartMenuFolder

;--------------------------------
; MUI Settings

  !define MUI_ABORTWARNING
  !define MUI_ICON "..\..\TopHappy\V3.0_TX\Installer\App.ico"
  ;!define MUI_UNICON "..\..\TopHappy\V3.0_TX\Installer\App.ico"

  !define PRODUCT_NAME "TopHappy"
  !define PRODUCT_VERSION "1.0"
  !define PRODUCT_WEB_SITE "http://www.happytop.cn/"
  !define PRODUCT_PUBLISHER "快乐至上科技发展有限公司"
  !define CONTROL_PANEL_NAME "快乐至上平台"

  !define PROGRAM_NAME "TxMainApp"
  !define PROGRAM_UNINSTALLER_NAME "Uninstall"
  !define PROGRAM_FULL_NAME "The ${PRODUCT_NAME} Penetration Test Platform"
  !define PROGRAM_NAME_PATH "${PROGRAM_NAME}.exe"
  !define PROGRAM_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PROGRAM_NAME}.exe"
  !define PROGRAM_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}"
  !define PROGRAM_UNINST_ROOT_KEY "HKLM"

;--------------------------------
; General

  Name "${CONTROL_PANEL_NAME}"
  ; outfile path
  OutFile "D:\Desktop\TxInstaller.exe"
  ; initialize dir when open
  InstallDir "$PROGRAMFILES\TopHappy"
  ; default reg
  InstallDirRegKey HKLM "${PROGRAM_DIR_REGKEY}" ""
  ; left corner display
  BrandingText "TopHappy.cn Installer"
  ; show installer info
  ShowInstDetails show
  ShowUnInstDetails show

;--------------------------------
; Pages

  !insertmacro MUI_PAGE_LICENSE "..\..\TopHappy\V3.0_TX\Installer\SoftwareLicence.txt"
  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY

  ;Start Menu Folder Page Configuration
  !define MUI_STARTMENUPAGE_REGISTRY_ROOT ${PROGRAM_UNINST_ROOT_KEY}
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PROGRAM_UNINST_KEY}"
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"

  !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder

  !insertmacro MUI_PAGE_INSTFILES
  !define MUI_FINISHPAGE_RUN
  ;
  !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
  !insertmacro MUI_PAGE_FINISH
  ;
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES

  Function LaunchLink
  ExecShell "" "$INSTDIR\${PROGRAM_NAME}.exe"
  FunctionEnd

;--------------------------------
; Language files

  !insertmacro MUI_LANGUAGE "SimpChinese"
;--------------------------------
; Hide Section

  ; Section "-Extra"
  ;   CreateDirectory "$INSTDIR\Installer"
  ;   SetOutPath "$INSTDIR\Installer"
  ;   SetOverwrite ifnewer
  ;   File /r "D:\TopHappy\V3.0_TX\Installer\nmap-7.12-setup.exe"
  ;   File /r "D:\TopHappy\V3.0_TX\Installer\HASPUserSetup.exe"
  ;   ExecWait "$INSTDIR\Installer\nmap-7.12-setup.exe"
  ;   ExecWait "$INSTDIR\Installer\HASPUserSetup.exe"
  ; SectionEnd

;--------------------------------
; Installer Section

  Section "主程序" SEC01
    SetShellVarContext current
    SetOutPath "$INSTDIR"
    SetOverwrite ifnewer
    File /r "D:\MyShare\20190829\Debug\*"

    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_DIR_REGKEY}" "" "$INSTDIR\${PROGRAM_NAME}.exe"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_DIR_REGKEY}" "Path" $INSTDIR

    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "DisplayName" "$(^Name)"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "UninstallString" "$INSTDIR\${PROGRAM_UNINSTALLER_NAME}.exe"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "DisplayIcon" "$INSTDIR\${PROGRAM_NAME}.exe"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
    WriteRegStr ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"


    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application

      ;Create shortcuts
      CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
      CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${CONTROL_PANEL_NAME}.lnk" "$INSTDIR\${PROGRAM_NAME}.exe"
      CreateShortCut "$SMPROGRAMS\$StartMenuFolder\${PROGRAM_UNINSTALLER_NAME}.lnk" "$INSTDIR\${PROGRAM_UNINSTALLER_NAME}.exe"

    !insertmacro MUI_STARTMENU_WRITE_END  

    CreateShortCut "$DESKTOP\${CONTROL_PANEL_NAME}.lnk" "$INSTDIR\${PROGRAM_NAME}.exe"
    WriteUninstaller "$INSTDIR\${PROGRAM_UNINSTALLER_NAME}.exe"

    ; Delete "$INSTDIR\Installer\nmap-7.12-setup.exe"
    ; Delete "$INSTDIR\Installer\HASPUserSetup.exe"
    ; RMDir "$INSTDIR\Installer"
  SectionEnd

;--------------------------------
; Descriptions

  ;Language strings
  LangString DESC_SecDummy ${MUI_LANGUAGE} "包含执行,脚本以及配置文件"

  ;Assign language strings to sections
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${SEC01} $(DESC_SecDummy)
  !insertmacro MUI_FUNCTION_DESCRIPTION_END


;--------------------------------

Function .onInit
  # set section 'test' as selected and read-only
  IntOp $0 ${SF_SELECTED} | ${SF_RO}
  SectionSetFlags ${SEC01} $0

  ${IfNot} ${RunningX64}
    MessageBox MB_OK "此版本只能运行在64位机器上.$\n请尝试安装32位版本." /SD IDOK
    Abort
  ${EndIf}

  ; Copied from https://nsis.sourceforge.io/Auto-uninstall_old_before_installing_new
  ReadRegStr $R2 ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "UninstallString"
  ReadRegStr $R1 ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "DisplayName"
  StrCmp $R2 "" NO YES
    YES:
    MessageBox MB_ICONQuESTION|MB_YESNO "$R1 已经被安装,是否进行卸载?" IDYES keep IDNO none
  keep:
    ; MessageBox MB_YESNO $R2
    ExecWait $R2
  none:
    Quit
    NO:
FunctionEnd


;--------------------------------
; getsize

  Section "-Finally"
    ; Compute and write the installation directory size
    ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
    IntFmt $0 "0x%08X" $0
    WriteRegDWORD ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}" "EstimatedSize" "$0"
  SectionEnd

;--------------------------------

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

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

Section "Uninstall"

  Delete "$INSTDIR\*"
  RMDir /r $INSTDIR

  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder

    ; uninstall startmenu shortcuts
    Delete "$DESKTOP\${CONTROL_PANEL_NAME}.lnk"
    Delete "$SMPROGRAMS\$StartMenuFolder\${PROGRAM_UNINSTALLER_NAME}.lnk"
    Delete "$SMPROGRAMS\$StartMenuFolder\${CONTROL_PANEL_NAME}.lnk"
    RMDir "$SMPROGRAMS\$StartMenuFolder"

  DeleteRegKey /ifempty ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_UNINST_KEY}"
  DeleteRegKey /ifempty ${PROGRAM_UNINST_ROOT_KEY} "${PROGRAM_DIR_REGKEY}"
  SetAutoClose false
  
SectionEnd