Launch custom code via tasks in Inno Setup
I want to execute some code if a user checks a corresponding checkbox during the install. From reading the help file, it looks like the only way to use the tas开发者_高级运维k is to associate it with an entry in the Files
/Icons
/etc. section. I'd really like to associate it with a procedure in the Code
section. Can this be done and if so, how?
You don't need to define your own wizard page. You can just add them to the additional tasks page.
[Tasks]
Name: associate; Description:"&Associate .ext files with this version of my program"; \
GroupDescription: "File association:"
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = wpSelectTasks then
begin
if WizardIsTaskSelected('taskname') then
MsgBox('First task has been checked.', mbInformation, MB_OK);
else
MsgBox('First task has NOT been checked.', mbInformation, MB_OK);
end;
end;
Credit goes to TLama for this post.
You do that by adding a custom wizard page that has check boxes, and execute the code for all selected check boxes when the user clicks "Next" on that page:
[Code]
var
ActionPage: TInputOptionWizardPage;
procedure InitializeWizard;
begin
ActionPage := CreateInputOptionPage(wpReady,
'Optional Actions Test', 'Which actions should be performed?',
'Please select all optional actions you want to be performed, then click Next.',
False, False);
ActionPage.Add('Action 1');
ActionPage.Add('Action 2');
ActionPage.Add('Action 3');
ActionPage.Values[0] := True;
ActionPage.Values[1] := False;
ActionPage.Values[2] := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = ActionPage.ID then begin
if ActionPage.Values[0] then
MsgBox('Action 1', mbInformation, MB_OK);
if ActionPage.Values[1] then
MsgBox('Action 2', mbInformation, MB_OK);
if ActionPage.Values[2] then
MsgBox('Action 3', mbInformation, MB_OK);
end;
end;
The check boxes can either be standard controls or items in a list box, see the Inno Setup documentation on Pascal Scripting for details.
If you want your code to be executed depending on whether a certain component or task has been selected, then use the WizardIsComponentSelected()
and WizardIsTaskSelected()
functions instead.
精彩评论