InnoSetup使用教程:InnoSetup打包安装
脚本详细
1. 定义变量
#define MyAppName "TranslationTool"
#define MyAppChineseName "翻译工具"
#define MyAppVersion "1.0"
#define MyAppPublisher "dotnetschool"
#define MyAppURL "https://dotnet-campus.github.io/"
#define MyAppExeName "TranslationTool.exe"
2. 初始化安装包设置
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppChineseName}
OutputDir=C:\Users\\Desktop
OutputBaseFilename={#MyAppChineseName}
SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
Compression=lzma
SolidCompression=yes
其中,
- AppId 程序标识
- AppName 程序名称
- AppVersion 版本号。生成默认版本号AppName+AppVersion
- AppVerName 程序版本号。如果设置了AppVersion,则AppVerName会覆盖AppVersion值。
- AppPublisher 发布者
- AppPublisherURL、AppSupportURL、AppUpdatesURL 相关链接
- DefaultDirName 默认安装目录
- DefaultGroupName 默认开始菜单目录名
- OutputDir 打包exe的生成目录,比如可以设置在桌面
- OutputBaseFilename 打包exe的文件名称
- SetupIconFile 设置打包exe的图标
- Compression、SolidCompression 压缩相关
3. 启动文件和程序所有文件
[Files]
Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
忽略文件 Excludes: "*.bak,*.pdb,*.dll.config,*.ax,*\Log\*";
4. 图标
[Icons]
Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
从上而下,分别是开始菜单中的启动快捷方式、开始菜单中的卸载快捷方式、桌面快捷方式
5. 直接启动
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent
在完成安装后,可以选择直接启动。
6. 添加Pascal代码
以上都只是innosetup提供的配置,如果需要定制注册表、卸载其它软件、定制界面、用户环境等,可以通过innosetup提供的一些事件来处理。如:
[code]
function InitializeSetup (): Boolean;
begin
MsgBox('程序安装!', mbInformation, MB_OK);
Result := true;
end;
此处只介绍一些常用的字段参数,详细的可参考其它博客:https://blog.****.net/yiyihuazi/article/details/60323746 、https://www.cnblogs.com/langtianya/p/4285570.html
案例脚本:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "TranslationTool"
#define MyAppChineseName "翻译工具"
#define MyAppVersion "1.0"
#define MyAppPublisher "dotnetschool"
#define MyAppURL "https://dotnet-campus.github.io/"
#define MyAppExeName "TranslationTool.exe" [Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppChineseName}
OutputDir=C:\Users\\Desktop
OutputBaseFilename={#MyAppChineseName}
SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
Compression=lzma
SolidCompression=yes [Languages]
Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files]
Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Icons]
Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent
设置安装包以管理员权限运行
如果安装包需要以管理员运行,在VS中设置程序以管理员权限启动之后,
在InnoSetup安装目录下,找到配置SetupLdr.e32文件,设置Manifest中的权限启动参数(与VisualStudio类似),操作如下:
下载Resource Hacker编译器,然后打开.e32文件,将其中权限相关参数,修改为管理员权限。
详细操作可参考:用inno setup制作管理员权限启动的安装包
案例截图
生成的安装包exe以及安装后桌面快捷方式
开始菜单中的快捷方式