安装文件制作工具NSIS 使用总结
 
在给客户开发客户端软件时,为避免技术人员亲自上门安装带来额外的成本损耗,通常我们都会自作一个安装包,以确保我们开发的程序的相关依赖资源、环境在客户端运行前能自动地正确配置好。
 
NSIS是一个比较流行的安装文件制作工具,制作简单,提供脚本语言来定义环境和程序的静态资源配置,使得安装文件可定制化, 并能根据自定义的脚本文件自动生成可执行的安装包, 大大地简化了程序员的发布工作。
 
NSIS提供了多个脚本demo,可在UI上直接打开来查看其demo 并学习。
 
其脚本指令基本都用于设置安装程序的几大部件: 安装程序标题, 默认安装目录,待copy的文件, 目标地址及目录结构,运行环境设置:注册表, 卸载时的操作:删除文件,注册表。
 
因此其对应的脚本指令大概有以下几类:
1. 安装程序标题: Name
2. 默认安装目录:InstallDir
3. 待copy的文件: File
4. 目标地址及目录结构:InstallDir 
5. 运行环境设置:注册表,快捷方式: WriteRegStr,CreateShortCut
6. 卸载时的操作:删除文件,目录,注册表: Delete,RMDir, DeleteRegKey
 
 
注意点:
1.  如果程序需安装在C盘,在win vista后续版本需要获取 admin 权限。
2. 如需在目标地址下添加目录,则需在创建目录后,设置新的输出目录。
         CreateDirectory $INSTDIR\mplayer
         SetOutPath $INSTDIR\mplayer
 
 
 
脚本代码实例如下:

 
 ; VRA.nsi
;
; This script is based on VRA.nsi, but it remember the directory, 
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install VRA.nsi into a directory that the user selects,

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

; The name of the installer
Name "VRA installer"
InstallDir "C:\VRA"

; The file to write
; OutFile "example2.exe"
OutFile "VRA_Installer.exe"
RequestExecutionLevel admin

; The default installation directory
;InstallDir $PROGRAMFILES\VRA

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\VRA" "Install_Dir"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

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

; Pages

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

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

; The stuff to install
Section "VRA (required)"

SectionIn RO

; Set output path to the installation directory.
SetOutPath $INSTDIR

; Put file there
;File "example2.nsi"
File "bz2.pyd"
File "MSVCP90.dll"
File "MSVCR90.dll"
File "msvcrt.dll"
File "pycpuid._pycpuid.pyd"
File "python27.dll"
File "pywintypes27.dll"
File "screen_left.bmp"
File "select.pyd"
File "unicodedata.pyd"
File "user32.dll"
File "VRA.exe"
File "VRA.exe.manifest"
File "win32api.pyd"
File "win32evtlog.pyd"
File "wx._controls_.pyd"
File "wx._core_.pyd"
File "wx._gdi_.pyd"
File "wx._misc_.pyd"
File "wx._windows_.pyd"
File "wxbase30u_net_vc90.dll"
File "wxbase30u_vc90.dll"
File "wxmsw30u_adv_vc90.dll"
File "wxmsw30u_core_vc90.dll"
File "wxmsw30u_html_vc90.dll"
File "_ctypes.pyd"
File "_hashlib.pyd"
File "_socket.pyd"
File "_ssl.pyd"
File "mplayer.exe"
CreateDirectory $INSTDIR\mplayer
SetOutPath $INSTDIR\mplayer
File "mplayer\config"
SetOutPath $INSTDIR

; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\VRA "Install_Dir" "$INSTDIR"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" Shell "$INSTDIR\VRA.exe"

; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\VRA" "VRA" "VRA"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\VRA" "Uninstall_VRA" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\VRA" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\VRA" "NoRepair" 1
WriteUninstaller "uninstall.exe"

SectionEnd

; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"

CreateDirectory "$SMPROGRAMS\VRA"
CreateShortCut "$SMPROGRAMS\VRA\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\VRA\VRA.lnk" "$INSTDIR\VRA.exe" "" "$INSTDIR\VRA.exe" 0

SectionEnd

; Optional section (can be disabled by the user)
Section "Desktop Shortcuts" SectionX

SetShellVarContext current
CreateShortCut "$DESKTOP\VRA.lnk" "$INSTDIR\VRA.exe"
;WriteRegStr HKLM "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\layers" "$INSTDIR\VRA.exe" "RUNASADMIN"
SectionEnd

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

; Uninstaller

Section "Uninstall"

; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\VRA"
DeleteRegKey HKLM SOFTWARE\VRA

; Remove files and uninstaller
;Delete $INSTDIR\example2.nsi
;Delete $INSTDIR\uninstall.exe
Delete "$INSTDIR\bz2.pyd"
Delete "$INSTDIR\Microsoft.VC90.CRT.manifest"
Delete "$INSTDIR\msvcm90.dll"
Delete "$INSTDIR\msvcp90.dll"
Delete "$INSTDIR\msvcr90.dll"
Delete "$INSTDIR\msvcrt.dll"
Delete "$INSTDIR\pycpuid._pycpuid.pyd"
Delete "$INSTDIR\python27.dll"
Delete "$INSTDIR\pywintypes27.dll"
Delete "$INSTDIR\screen_left.bmp"
Delete "$INSTDIR\select.pyd"
Delete "$INSTDIR\unicodedata.pyd"
Delete "$INSTDIR\user32.dll"
Delete "$INSTDIR\VRA.exe"
Delete "$INSTDIR\VRA.exe.manifest"
Delete "$INSTDIR\win32api.pyd"
Delete "$INSTDIR\win32evtlog.pyd"
Delete "$INSTDIR\wx._controls_.pyd"
Delete "$INSTDIR\wx._core_.pyd"
Delete "$INSTDIR\wx._gdi_.pyd"
Delete "$INSTDIR\wx._misc_.pyd"
Delete "$INSTDIR\wx._windows_.pyd"
Delete "$INSTDIR\wxbase30u_net_vc90.dll"
Delete "$INSTDIR\wxbase30u_vc90.dll"
Delete "$INSTDIR\wxmsw30u_adv_vc90.dll"
Delete "$INSTDIR\wxmsw30u_core_vc90.dll"
Delete "$INSTDIR\wxmsw30u_html_vc90.dll"
Delete "$INSTDIR\_ctypes.pyd"
Delete "$INSTDIR\_hashlib.pyd"
Delete "$INSTDIR\_socket.pyd"
Delete "$INSTDIR\_ssl.pyd"
Delete "$INSTDIR\mplayer.exe"
Delete "$INSTDIR\mplayer\config"
Delete "init.check"
Delete "init.video"
Delete "kamhearing.log"
Delete "player_reg.dll"
Delete "uninstall.exe"

; Remove shortcuts, if any
Delete "$SMPROGRAMS\VRA\*.*"
Delete "$SMPROGRAMS\VRA\VRA.lnk"

; Remove directories used
RMDir "$SMPROGRAMS\VRA"
RMDir "$INSTDIR\mplayer"
RMDir "$INSTDIR"

SectionEnd

最新文章

  1. @echo off 与echo off
  2. git命令大全
  3. 5种风格的 jQuery 分页效果【附代码】
  4. Linux Native Aio 异步AIO的研究
  5. 兼容ie7的导航下拉菜单
  6. Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) B. Guess the Permutation 水题
  7. tomcat初识
  8. Servlet3.0学习总结(三)——基于Servlet3.0的文件上传
  9. 某Python群的入群题目
  10. 网页HTML1
  11. 《第一行代码》学习笔记15-UI(4)
  12. JMS理解2
  13. Jenkins 远程构建任务
  14. vscode 同步配置插件
  15. rand和randn
  16. HDU-1011 Starship Troopers(树形dp)
  17. 软件工程作业 - 实现WC功能(java)
  18. 撩课-Web大前端每天5道面试题-Day24
  19. Unix IPC之Posix消息队列(1)
  20. html 中的列表

热门文章

  1. CAD中批量打印
  2. ubuntu下配置华为交换机s2016
  3. Struts2(九)OGNL标签一与Struts2标签
  4. 通过实例看懂diff命令输出
  5. 关于 qtchooser
  6. SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释(转)
  7. 转:体积阴影(Shadow Volumes)生成算法
  8. shell 脚本启动spring boot的jar 包
  9. ios中二维码的用法
  10. (原)tensorflow中提示CUDA_ERROR_LAUNCH_FAILED