Inno Setup 打包使用说明

用一句话理解:Inno Setup 把你已经编译好的程序,打成 Windows 安装包(Setup.exe)。
它不负责编译代码,只负责安装、卸载、写快捷方式、选安装目录这些事。

适用:把 exe / dll / 配置 / 资源打成可分发安装程序。
不适合:macOS / Linux 安装包(那是别的工具的事)。


1 · 它是干什么的

你有什么 Inno Setup 帮你做什么
已编译的 MyApp.exe 和一堆依赖文件 打成一个 MyApp-Setup.exe
希望用户双击安装 安装向导、选目录、开始菜单、桌面图标
希望能干净卸载 生成卸载程序,写注册表卸载项
TIP

📌 和 NSIS / WiX 的关系:都是 Windows 安装包工具。Inno Setup 脚本好读、上手快,个人项目和中小软件很常见。Tauri 默认常用 NSIS;如果你要自己控安装流程,Inno Setup 很合适。


2 · 安装与准备

2.1 下载安装

  1. 打开官网:https://jrsoftware.org/isinfo.php
  2. 下载 Inno Setup(建议最新稳定版)
  3. 安装时建议勾选:
    • Inno Setup Preprocessor(预处理,脚本更灵活)
    • 中文语言包(若安装程序提供)

装好后会有:

  • Inno Setup Compiler:写脚本、点 Compile 出安装包
  • 可选 Inno Script Studio 等第三方编辑器(不是必须)

2.2 你需要先准备好的东西

打包前,程序本身要先能跑:

release/                 # 示例发布目录
├── MyApp.exe            # 主程序
├── *.dll                # 依赖(如有)
├── config/              # 配置或资源
└── README.txt           # 可选

另外准备:

  • 应用图标 .ico(安装包/快捷方式用)
  • 许可协议 .txt(可选)
  • 安装包显示名、版本号、发布者名称

3 · 最快上手:5 分钟打出第一个安装包

3.1 新建脚本

打开 Inno Setup Compiler → File → New
可走向导(Wizard),也可直接新建空 .iss 文件。

把下面脚本存成 MyApp.iss,路径按你的实际目录改:

; 基本信息
#define MyAppName "我的应用"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "RyB"
#define MyAppExeName "MyApp.exe"

[Setup]
AppId={{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputDir=output
OutputBaseFilename=MyApp-Setup-{#MyAppVersion}
Compression=lzma2
SolidCompression=yes
WizardStyle=modern
PrivilegesRequired=admin
ArchitecturesInstallIn64BitMode=x64compatible
SetupIconFile=setup.ico
UninstallDisplayIcon={app}\{#MyAppExeName}

[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
; 若没有中文语言文件,可先用:
; Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "创建桌面快捷方式"; GroupDescription: "附加任务:"; Flags: unchecked

[Files]
; 把发布目录整包拷进安装目录
Source: "release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
; 安装结束可勾选“立即运行”
Filename: "{app}\{#MyAppExeName}"; Description: "立即运行 {#MyAppName}"; Flags: nowait postinstall skipifsilent

3.2 编译

  1. 菜单 Build → Compile(或快捷键)
  2. 成功后在 output\ 下得到:MyApp-Setup-1.0.0.exe
  3. 双击安装包自测:安装 → 启动 → 卸载

4 · 脚本分段说明(够用就行)

段 作用
#define 宏变量,版本号、名字写一处,处处用
[Setup] 安装包核心配置:目录、输出名、压缩、权限
[Languages] 安装向导语言
[Tasks] 可选任务,如桌面图标
[Files] 最重要:哪些文件装到哪里
[Icons] 开始菜单 / 桌面快捷方式
[Run] 安装完成后运行什么
[Code] Pascal 脚本,做自定义逻辑(进阶)
[Registry] 写注册表(进阶,能不用就少用)

4.1 几个常用常量

常量 含义
{app} 用户选的安装目录
{autopf} 自动选的 Program Files(32/64 会处理)
{userappdata} 当前用户 AppData\Roaming
{localappdata} 当前用户 AppData\Local
{tmp} 临时目录
{group} 开始菜单程序组
{autodesktop} 桌面(自动区分)

4.2 [Files] 常用 Flags

Flag 含义
ignoreversion 不比较版本,直接覆盖(开发期常用)
recursesubdirs 包含子目录
createallsubdirs 空目录也创建
onlyifdoesntexist 已存在则不覆盖(适合用户配置)
uninsneveruninstall 卸载时保留(日志/用户数据要谨慎)

示例:程序文件可覆盖,用户配置不覆盖:

[Files]
Source: "release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "release\config\default.ini"; DestDir: "{app}\config"; Flags: onlyifdoesntexist

5 · 实际打包时要注意的细节

5.1 AppId 不要乱改

AppId={{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}
  • 同一款软件升级安装包应保持 同一个 AppId
  • 换了 AppId,Windows 会当成另一个软件,卸载项会乱
  • 用自己的 GUID,不要直接抄别人的

生成 GUID 可用 PowerShell:

[guid]::NewGuid().ToString().ToUpper()

5.2 64 位程序

ArchitecturesInstallIn64BitMode=x64compatible
ArchitecturesAllowed=x64compatible

只给 64 位系统装时加上 ArchitecturesAllowed,避免装到不支持的机器上。

5.3 要不要管理员权限

场景 建议
装到 Program Files PrivilegesRequired=admin
只装当前用户目录 PrivilegesRequired=lowest,目录用 {localappdata}\...

绿色软件、不想弹 UAC,优先 per-user 安装。

5.4 版本号与输出文件名

AppVersion=1.2.3
OutputBaseFilename=MyApp-Setup-1.2.3

建议和程序内版本一致,方便排查用户装的是哪一版。

5.5 依赖运行库

若程序依赖 VC++ 运行库、.NET 等:

  • 要么安装包里带 redist 并静默安装
  • 要么文档写明“请先安装 xxx”
  • 不要假设用户机器上一定有

VC++ 示例思路(需自备安装包路径):

[Files]
Source: "redist\vc_redist.x64.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall

[Run]
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/install /quiet /norestart"; StatusMsg: "正在安装运行库..."; Flags: waituntilterminated

5.6 中文界面

语言文件一般在 Inno 安装目录的 Languages\ChineseSimplified.isl。
若编译报找不到语言文件:

  1. 确认 Inno 版本是否带该语言包
  2. 或先改用 Default.isl(英文向导)

5.7 命令行静默安装(给脚本/批量用)

MyApp-Setup-1.0.0.exe /SILENT
MyApp-Setup-1.0.0.exe /VERYSILENT /NORESTART
MyApp-Setup-1.0.0.exe /DIR="D:\Apps\MyApp"
参数 含义
/SILENT 静默,进度窗可能还在
/VERYSILENT 更静默
/DIR=路径 指定安装目录
/NORESTART 尽量不重启

6 · 推荐目录结构(项目里这样放)

MyApp/
├── release/                 # 编译输出(被打包的内容)
│   ├── MyApp.exe
│   └── ...
├── installer/
│   ├── MyApp.iss            # Inno 脚本
│   ├── setup.ico
│   └── license.txt
└── output/                  # 生成的 Setup.exe(可 gitignore)

脚本里:

Source: "..\release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
OutputDir=..\output

7 · 命令行编译(CI / 一键脚本)

Inno 安装后一般有 ISCC.exe:

# 路径按本机安装位置改
& "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" ".\installer\MyApp.iss"

成功会在 OutputDir 生成安装包。
可把这行写进 build-installer.ps1,和编译步骤串起来。


8 · 签名(可选但正式发布建议做)

未签名的 Setup.exe 容易被 SmartScreen 拦截。

  1. 准备代码签名证书
  2. 用 signtool 签 安装包(以及主程序 exe 更好)
signtool sign /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 /a ".\output\MyApp-Setup-1.0.0.exe"

具体证书与时间戳服务器以你购买的证书厂商为准。


9 · 常见问题

现象 可能原因 处理
编译失败找不到文件 Source 路径不对 用相对 .iss 的路径,或写绝对路径试一次
安装后双击没反应 少 dll / 运行库 在干净虚拟机里测;用依赖工具查缺什么
卸载后还有文件 运行中锁定,或 Flags 保留 退出程序再卸;检查 uninsneveruninstall
升级没覆盖旧文件 版本比较逻辑 开发期可用 ignoreversion
杀软误报 未签名 + 压缩壳特征 签名;减少无意义加壳;提交白名单
中文乱码 脚本编码问题 .iss 用 UTF-8 BOM(Inno 6 常用)

10 · 最小检查清单(发版前)

  1. 干净 Windows(或虚拟机)双击 Setup 能装
  2. 开始菜单能启动,桌面图标可选
  3. 装到非默认目录也能跑
  4. 卸载干净(用户数据是否保留要符合产品设计)
  5. 版本号、安装包文件名、关于页一致
  6. 正式对外:尽量代码签名

11 · 和 TooBox / Tauri 的关系(备忘)

方案 说明
Tauri 自带 NSIS too-box-new 当前打包路线,和自动更新集成方便
自己上 Inno Setup 安装向导自定义多、老项目常见、脚本直观
可以并存 例如内部渠道用 Inno,正式桌面端继续 Tauri NSIS

选工具的核心不是“哪个更高级”,而是:安装体验、签名、自动更新、团队是否熟。


12 · 官方与延伸


附录 · 再精简的“只拷贝 exe”脚本

只有一个绿色 exe 时:

[Setup]
AppName=小工具
AppVersion=1.0.0
AppId={{11111111-2222-3333-4444-555555555555}
DefaultDirName={localappdata}\SmallTool
PrivilegesRequired=lowest
OutputDir=output
OutputBaseFilename=SmallTool-Setup
Compression=lzma2
SolidCompression=yes
WizardStyle=modern

[Files]
Source: "SmallTool.exe"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{autodesktop}\小工具"; Filename: "{app}\SmallTool.exe"

装到用户目录、不弹管理员 UAC,适合小工具。


写给需要快速打 Windows 安装包的同事:先保证 release 能跑,再写 [Files],最后才考虑签名和静默参数。