Write "true"/"false" to an INI file based on task selection in Inno Setup

Viewed 105

In the [Tasks] section I have:

[Tasks]
Name: "userexpericeneimprovement"; \
    Description: "{cm:JoinUserExpericeneImprovement}"; \
    GroupDescription: "{cm:AdditionalIcons}"; MinVersion: 0.0,5.0;

and in [INI] is this specific command:

[INI]
FileName: "{app}\ceip.ini"; Section: "General"; Key: "enabled"; \
    String: "{code:GetUserJoin}";

My aim is to check the selected task and then the [Code] {code:GetUserJoin} part will do the filling in the ceip.ini file as "true" or "false" whichever is checked or unchecked.

1 Answers

This is trivial enough to be implemented even without any Pascal Script with use of Tasks parameter:

[INI]
FileName: "{app}\ceip.ini"; Section: "General"; Key: "enabled"; String: "true"; \
    Tasks: userexpericeneimprovement
FileName: "{app}\ceip.ini"; Section: "General"; Key: "enabled"; String: "false"; \
    Tasks: not userexpericeneimprovement

If you want to use the Pascal Script, the implementation is also trivial with use of WizardIsTaskSelected function:

[INI]
FileName: "{app}\ceip.ini"; Section: "General"; Key: "enabled"; \
    String: "{code:GetUserJoin}";
[Code]
function GetUserJoin(Param: string): string;
begin
  if WizardIsTaskSelected('userexpericeneimprovement') then Result := 'true'
    else Result := 'false';
end;
Related