My goal is to create an installer that both can come up with a conditional parameter at startup but can have a checkable task too.
Via an optional parameter /NOAUTOSTART
the installer should skip creating an entry in the Registry which lets the tool start at Windows login.
Additionally this feature should be able to be toggled via a Task and lets the user decide, whether this feature should be enabled or not.
Furthermore, if the parameter /NOAUTOSTART
is passed while executing the installer, this task/window should be skipped anyways, therefore overruling this screen.
How is that possible?
I've been coming up with the following solution sofar:
[Tasks]
Name: autostartWhenChecked; Description: "Automatically start agent on login"
[Registry]
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; \
ValueType: string; ValueName: "Updater Agent"; \
ValueData: """{app}\Agent.exe"""; Flags: uninsdeletevalue; \
Tasks: autostartWhenChecked;
This successfully handles the checkbox in my installer.
But in combination with the following, retrieving the startup parameter (thanks to this answer: Passing conditional parameter in Inno Setup):
[Code]
function CmdLineParamExists(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Value) = 0 then
begin
Result := True;
Exit;
end;
end;
function ShouldEnableAutostart: Boolean;
begin
if CmdLineParamExists('/NOAUTOSTART') then
begin
Checkbox :=
WizardForm.TasksList.Items.IndexOf(
'Automatically start agent on login');
WizardForm.TasksList.CheckItem(Checkbox, coUncheck);
Result := False;
end
else
Result := True;
end;
I can't combine those two possibilities. Furthermore I'm struggling on how to get the index of the task, the code above always returns an index out of bounds (-1). Seems like the description text of the task can't be found anyhow.