从简单到完整,Liam平平带你一步步制作完美安装包, 万事开头难。

第一课:制作一个安装包,运行后将安装包中文件安装到指定位置。

一、 下载安装NSIS

官方下载地址:https://nsis.sourceforge.io/Download

二、编写脚本

  1. 新建一个脚本文件, 如:test1.nsi
; The name of the installer
Name "HelloLiam"

; The file to write
OutFile "hello_liam_setup.exe"

; Request application privileges for Windows Vista
RequestExecutionLevel user

; Build Unicode installer
Unicode True

; The default installation directory
InstallDir $PROGRAMFILES64\HelloLiam

;Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages

Page directory
Page instfiles

;--------------------------------
; The stuff to install
Section "" ;No components page, name is not important
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  ; Put file there
  ;File HelloLiam.exe ;add a file.
  File /r "InstallFiles\*.*" 
SectionEnd ; end the section

 

  1. 准备需要打包的文件,示例放在脚本同目录的InstallFiles文件夹下

v2-d1228dd77dc93be883702f56b7f7b2aa_720w

需要打包的文件:

v2-422b9c18aec116d0a620f499ee09fb85_720w

  1. 编辑脚本:推荐使用VS Code安装代码高亮插件。

三、 运行脚本生成安装包

  1. 打开NSIS软件

v2-7d173bb36f54307db1f54e5b95763fed_720w

  1. 打开示例test1.nsi

v2-38a8ad5d90f2c46be3cbec0e4e7d16aa_720w-1

  1. 生成exe安装包

v2-12f776f4281aea34130ef2c89d5c5d4f_720w

四、测试安装

  1. 直接点击测试安装,或手动运行exe安装包
  2. 路径选择界面:

v2-acb5d301a7c2d9361a418f898d2eca35_720w

  1. 安装完成界面

v2-e5d153a0e2818377b84123ba82b603a4_720w

  1. 安装后的效果

v2-83256562d2b1d81a5f65d62ffca605f5_720w

End

欢迎查看后期教程:

  1. 创建快捷方式。
  2. 创建卸载程序。
  3. 界面美化。
  4. 判断是否正在运行。
  5. 判断并安装VC运行库。

作者 admin

发表评论

您的电子邮箱地址不会被公开。