目录
介绍
很长一段时间以来,我都没有意识到Inno Setup [Tasks]的用处,我使用自定义页面来处理更复杂的设置场景。
最近,我决定试一试[Tasks],发现它可以使一些安装场景变得简单得多。
使用代码
在下面的代码中,显示了一些无害的虚拟应用程序的最小示例。该代码应适用于Inno Setup v5或更高版本。此外,虚拟应用程序的代码在这里并不重要,但对于那些感兴趣的人,我已经包含了VS2022代码。
当用户选择“客户端”选项时,不会显示“任务”页。当用户选择“服务器”选项时,将显示“任务”页面,选中“Postgres”选项后,将在“服务器”应用之前“安装”Postgres。
;
; Test [Tasks] for Inno Setup
; Simulates a simple Client or Server installation using dummy .exe files.
;
#define MyAppName "Tasks_Test"
#define MyAppVersion "1.0"
#define MyAppPublisher "RickZeeland"
[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={{CEB74C97-297E-49DA-AD56-CB816A92E20B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf64}\{#MyAppName}
DefaultGroupName={#MyAppName}
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputBaseFilename=Tasks_Test
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ArchitecturesAllowed=x64
; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64
; Do not ask for PC restart.
RestartIfNeededByRun=no
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Types]
; Prevent showing the Types ComboBox
Name: "custom"; Description: "Custom installation"; Flags: iscustom
[Components]
Name: "client"; Description: "Client"; Flags: exclusive
Name: "server"; Description: "Server"; Flags: exclusive
[Tasks]
; The postgres Task page is only shown when server is selected
Name: "postgres"; Description: "PostgreSQL installation"; Components: server
[Files]
Source: "ClientDummy.exe"; DestDir: "{app}"; Components: client; Flags: ignoreversion
Source: "ServerDummy.exe"; DestDir: "{app}"; Components: server; Flags: ignoreversion
; Postgres dummy is only installed when server is selected and task postgres is checked
Source: "PostgresDummy.exe"; DestDir: "{app}"; Tasks: postgres; Flags: ignoreversion
[Icons]
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
[Run]
Filename: "{app}\PostgresDummy.exe"; Description: "{cm:LaunchProgram, Postgres dummy app}"; Tasks: postgres; Flags: waituntilterminated postinstall skipifsilent
Filename: "{app}\ClientDummy.exe"; Description: "{cm:LaunchProgram, Client dummy app}"; Components: client; Flags: nowait postinstall skipifsilent
Filename: "{app}\ServerDummy.exe"; Description: "{cm:LaunchProgram, Server dummy app}"; Components: server; Flags: nowait postinstall skipifsilent
兴趣点
要在Inno Setup [Code]部分中访问Tasks,可以使用以下命令:
IsTaskSelected('postgres')
从Windows“开始”菜单或“设置”中,Tasks_Test可以卸载。
https://www.codeproject.com/Tips/5370107/Inno-Setup-Tasks-Demystified