1.下载工具和语言包
官方下载地址:Inno Setup Downloads下载完成后,点击exe文件直接安装即可。
默认info setup是没有中文包的,可以在Inno Setup Translations选择需要的语言包下载,放到info setup安装目录Languages文件夹下。
2.打包
(1)提前准备好编译好的程序,即winform程序下的debug文件夹;
(2)打包可以分为两种,一种是直接用info setup的例子,直接修改脚本,但是初次使用用户建议new一个新的,以下教程是new的例子。
项目名称、版本、单位、单位网址这些可以在这里更改,后续也可以在脚本内更改
设置安装目录和文件夹名称,后续也可以在脚本内更改
设置打包的程序:
Application main executable file: 选择debug程序中要执行的exe
Other application files: 选择debug文件夹和额外需要的包,例如我这里需要.net framework4.5.2,所以将dotNetFx40_Full_x86_x64.exe也添加到里面。
此步骤可以忽略
设置是否创建桌面快捷程序等,默认即可
默认next即可,License file可以添加版权说明的txt
选择安装模式(默认就行)
选择语言,如果下载了中文语言包放到Languages文件夹下,在这里是可以选择的,默认是没有中文的
设置安装包存放位置,安装包名称,图标,密码(密码可以不设置)
再次点击next,会生成一个脚本,可以修改脚本信息
点击开始,开始打包安装程序
以下为我用过的脚本信息,参考了这位博主的文章,添加了判断有没有.netframework环节,没有则安装Inno Setup打包winform、wpf程序可判断VC++和.net环境_inno setup 安装net4.5.2-CSDN博客
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "testSetUp"
#define MyAppVersion "1.0"
#define MyAppPublisher "我的公司"
#define MyAppURL "http://example.com/"
#define MyAppExeName "testSetUp.exe"
#define MyAppAssocName MyAppName + ""
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.注意:AppId的值为每个程序不同,这里示例给出的必须被你自己的程序替换
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AF9D0E77-B350-4797-B57C-9AB94F042B93}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=D:\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=输出目录
OutputBaseFilename=输出文件夹名称
SetupIconFile=图标位置
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
;英文
Name: "english"; MessagesFile: "compiler:Default.isl"
;中文
;Name: "ChineseSimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
;debug执行de1exe
Source: "XXX\Debug\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
;debug文件夹目录
Source: "XX\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
;.netframework4.5.2安装程序目录
Source: "XX\dotNetFx40_Full_x86_x64.exe"; DestDir: "{tmp}";DestName:"dotnet452.exe"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[Code]
//.net framework安装检查 —— 判断指定的.NET Framework版本及service pack是否已经安装
// 函数参数说明:
// 参数1:version -- 指定待判断的.NET Framework版本【下面列举了对应关系】:
// 'v1.1' .NET Framework 1.1
// 'v2.0' .NET Framework 2.0
// 'v3.0' .NET Framework 3.0
// 'v3.5' .NET Framework 3.5
// 'v4\Client' .NET Framework 4.0 Client Profile
// 'v4\Full' .NET Framework 4.0 Full Installation
// 'v4.5' .NET Framework 4.5
// 'v4.5.1' .NET Framework 4.5.1
// 'v4.5.2' .NET Framework 4.5.2
// 'v4.6' .NET Framework 4.6
// 'v4.6.1' .NET Framework 4.6.1
// 'v4.6.2' .NET Framework 4.6.2
// 'v4.7' .NET Framework 4.7
// 'v4.7.1' .NET Framework 4.7.1
// 'v4.7.2' .NET Framework 4.7.2
// `v4.8` .NET Framework 4.8
//
// 参数2:service -- 指定待判断的service pack版本:
// 0 No service packs required
// 1, 2, etc. Service pack 1, 2, etc. required
function IsDotNetDetected(version: string; service: cardinal): boolean;
var
key, versionKey: string;
install, release, serviceCount, versionRelease: cardinal;
success: boolean;
begin
versionKey := version;
versionRelease := 0;
// .NET 1.1 and 2.0 embed release number in version key
if version = 'v1.1' then begin
versionKey := 'v1.1.4322';
end else if version = 'v2.0' then begin
versionKey := 'v2.0.50727';
end
// .NET 4.5 and newer install as update to .NET 4.0 Full
else if Pos('v4.', version) = 1 then begin
versionKey := 'v4\Full';
case version of
'v4.5': versionRelease := 378389;
'v4.5.1': versionRelease := 378675; // 378758 on Windows 8 and older
'v4.5.2': versionRelease := 379893;
'v4.6': versionRelease := 393295; // 393297 on Windows 8.1 and older
'v4.6.1': versionRelease := 394254; // 394271 before Win10 November Update
'v4.6.2': versionRelease := 394802; // 394806 before Win10 Anniversary Update
'v4.7': versionRelease := 460798; // 460805 before Win10 Creators Update
'v4.7.1': versionRelease := 461308; // 461310 before Win10 Fall Creators Update
'v4.7.2': versionRelease := 461808; // 461814 before Win10 April 2018 Update
'v4.8': versionRelease := 528040;
end;
end;
// installation key group for all .NET versions
key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + versionKey;
// .NET 3.0 uses value InstallSuccess in subkey Setup
if Pos('v3.0', version) = 1 then begin
success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
end else begin
success := RegQueryDWordValue(HKLM, key, 'Install', install);
end;
// .NET 4.0 and newer use value Servicing instead of SP
if Pos('v4', version) = 1 then begin
success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
end else begin
success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
end;
// .NET 4.5 and newer use additional value Release
if versionRelease > 0 then begin
success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
success := success and (release >= versionRelease);
end;
result := success and (install = 1) and (serviceCount >= service);
end;
//安装包初始化
function CheckDotNet(): Boolean;
var Path:string ;
ResultCode: Integer;
Success:Boolean;
begin
Success:=true;
if not IsDotNetDetected('v4.5.2', 0) then
begin
MsgBox('软件运行需要 Microsoft .NET Framework 4.5.2, 即将开始安装.NET Framework。', mbInformation, MB_OK);
ExtractTemporaryFile('dotnet452.exe');
Path:=ExpandConstant('{tmp}\dotnet452.exe')
Exec(Path, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
if not IsDotNetDetected('v4.5.2', 0) then
begin
if MsgBox('.Net Framework4.5.2组件安装失败,无法运行程序,是否继续安装!',mbInformation,MB_YESNO) = IDYES then
begin
Success:=true
end else
begin
Success := false;
result:=Success;
Exit;
end;
end
else
Success := true;
end
else
Success := true;
result := Success;
end;
function InitializeSetup: Boolean;
begin
Result := CheckDotNet();
end;