1

I want to know, if there is a way to add some command line parameters to Inno Setup based installer for /VERYSILENT mode, if for example I have theses checks:

Source: "{app}\Portable-File.exe"; DestDir: "{app}"; MinVersion: 0.0,5.0; Check: install1;
Source: "{app}\Installer-File.exe"; DestDir: "{app}"; MinVersion: 0.0,5.0; Check: porta1;

And I have these lines based in my two examples checks:

"MyProgram.exe" /VERYSILENT /install1 /EN
"MyProgram.exe" /VERYSILENT /porta1 /EN
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Joshua
  • 277
  • 1
  • 9

1 Answers1

2

Implement the install1 and porta1 functions like:

function HasCommandLineSwitch(Name: string): Boolean;
var
  I: Integer;
begin
  Result := False;

  for I := 1 to ParamCount do
  begin
    if CompareText(ParamStr(I), '/' + Name) = 0 then
    begin
      Result := True;
      Break;
    end;
  end;
end;

function install1: Boolean;
begin
  Result := HasCommandLineSwitch('install1');
end;

function porta1: Boolean;
begin
  Result := HasCommandLineSwitch('porta1');
end;

You can actually use the HasCommandLineSwitch directly in the Check parameter:

[Files]
Source: "Portable-File.exe"; DestDir: "{app}"; Check: HasCommandLineSwitch('install1')
Source: "Installer-File.exe"; DestDir: "{app}"; Check: HasCommandLineSwitch('porta1')

Though I assume that your install1 and porta1 function will actually do more than just call HasCommandLineSwitch, so this is probably not applicable to you.


Actually, as I know that you have checkboxes that correspond to install1 and porta1, what you really want to do, is to check those checkboxes, when the installer is starting, if the switches are specified. This way you can use /install1 and /porta1 to set default values, even if not used in combination with /verysilent. And it will still work even in the /verysilent mode, even though the user will actually never see the checkboxes (they are still present, even though not visible)

install1 := TNewRadioButton.Create(WizardForm); 
install1.Checked := HasCommandLineSwitch('install1');

porta1 := TNewRadioButton.Create(WizardForm); 
porta1.Checked := HasCommandLineSwitch('porta1');

And you keep your install1 and porta1 function to return the state of the checkboxes, as seen in Inno Setup Set Uninstallable directive based on custom checkbox value.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • when i use for exemple command line /verysilent /porta1, it s creates uninstallation files, it extract all portable files but it gets installed in the system – Joshua Sep 21 '17 at 05:47
  • Sorry, but I do not understand. What do you mean by *"but it gets installed in the system"* - What's wrong about that? + How is the behavior different to running an interactive installer and selecting the "porta1" option? - Show us a log file for both scenarios + If you have a problem, we need [mcve]. – Martin Prikryl Sep 21 '17 at 05:51
  • This doesnt work when im using /verysilent /porta1: `[Setup] Uninstallable=IsUninstallable` – Joshua Sep 21 '17 at 06:19
  • 1
    You should do what I have suggested in the last part of my answer. This first part is a generic answer to your *literal* question. But with knowing, what you installers does (and what you failed to explain in your question), I know that the first part won't help. That's why I've included another answer to a question, you *should have asked*. – Martin Prikryl Sep 21 '17 at 06:25
  • Only the last. For all your `installer*` and `portable*` `TNewRadioButton`'s, you have to do that. Instead of your current `Checked:=True;` and `Checked:=False` for `installer*`; and add the same for `portable*` – Martin Prikryl Sep 21 '17 at 06:58
  • You do not have any `porta1` radio button. In your code it's `portablefree`. But obviously I could not have known that from your question. That's why my answer shows a different identifier. And you should use the syntax within the `with` block anyway, the way you set `Checked:=True`/`False` for the `installerfree` and `installerbusiness` already, as I've suggested you already! + And yes, the `HasCommandLineSwitch` has to be defined above the `InitializeWizard`. – Martin Prikryl Sep 21 '17 at 07:42
  • 1
    This is not a code writing service. You have to ask a clear question to get a clear answer. Anyway, while your code would work, it';s indeed not correct. Use just `Checked := HasCommandLineSwitch('portablefree');`, not `portablefree.Checked := HasCommandLineSwitch('portablefree');`. The `portablefree.` is implied by the `with portablefree do`, what's why you have it there. See how you set `Checked` in the `with installerfree do` block. – Martin Prikryl Sep 21 '17 at 08:12
  • All work more or less, portablefree and portablebusiness get installed in windows as installerfree and installerbusiness [Code](https://paste.ee/p/nrEA8) – Joshua Sep 21 '17 at 12:22
  • 1
    For the option that should be selected by default, you should reverse the test: check it if no other is checked. At the end of the `InitalizeWizard` do something like `portablebusiness.Checked := (not portablefree.Checked) and (not installerfree.Checked) and (not installerbusiness.Checked);` – Martin Prikryl Sep 21 '17 at 12:24