16

I know there is the WizardSilent function for checking whether the setup runs in silent mode, but I cannot find a function equivalent for very silent mode (when the setup is executed with /VERYSILENT command line parameter).

Is there a way to detect whether the setup runs in very silent mode?

TLama
  • 75,147
  • 17
  • 214
  • 392
Vingt_centimes
  • 326
  • 2
  • 8

2 Answers2

17

WizardSilent will be true for both /Silent and /VerySilent installs. The difference between the two parameters is whether a progress bar is shown (/Silent) or not (/VerySilent).

Based on your comment, the best I can suggest would be to check the command line and look for /VerySilent and set a global variable. Something like:

[Code]
var 
  isVerySilent: Boolean;

function InitializeSetup(): Boolean;
var
  j: Integer;
begin
  isVerySilent := False;
  for j := 1 to ParamCount do
    if CompareText(ParamStr(j), '/verysilent') = 0 then
    begin
      isVerySilent := True;
      Break;
    end; 

  if isVerySilent then
    Log ('VerySilent')
  else
    Log ('not VerySilent');
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
mirtheil
  • 8,952
  • 1
  • 30
  • 29
  • The reason is that my installer launches an exe at the end, whose behavior changes if /SILENT or /VERYSILENT is there. But I can't pass the information to the exe if I can't determine it from the inno setup script. – Vingt_centimes Jul 12 '12 at 13:26
  • The problem with this is, it can't be used on uninstall, since most uninstaller code is actually ran and evaluated on installation. – Nyerguds Apr 03 '13 at 06:52
  • 1
    @Tom, this code works fine. If the user passes `/verysilent` parameter, there must be more than 1 parameter in the `ParamStr` collection since the first one `ParamStr(0)` is reserved for application file name. – TLama Oct 15 '14 at 09:35
  • 1
    @TLama: no, Tom is right... it doesn't break on finding the parameter, so any parameter given *after* the `/verysilent` will put the `isVerySilent` boolean to `false` again. There is literally no reason at all to ever put `isVerySilent := false;` inside the loop; it should be initialized to `false` in advance. – Nyerguds Jan 15 '15 at 11:22
  • @Nyerguds, you are right. I didn't read his comment well and addressed a different issue. However, he did not exit the loop either in his answer. You should write a [`helper function`](http://stackoverflow.com/a/18832316/960757) for that. – TLama Jan 15 '15 at 11:29
  • @TLama I wasn't saying Tom's own answer was more correct; just that his remark here was valid ;) Though, despite not breaking either (and the case sensitivity and starting from param 0 issues), his code never puts the boolean back to `false`, at least. – Nyerguds Jan 15 '15 at 11:34
  • @Nyerguds, yup, I got it :) Thanks for correcting me! Anyway, Tom initializes result on the first line. What he's missing there is that loop break when he finds the match. You don't need to change the value of the result if the iterated parameter does not match. You can initialize the result and change its value just when you find a match. If this happens, you break the loop. Sorry for confusion. I've fixed this post. I would fix his post too, but then it would be same as this one, and his note that *this one works better* would not be valid anymore :) – TLama Jan 15 '15 at 11:48
1

This one works better... its compatible with multiple params in command line

var
j: Cardinal;
begin

isVerySilent := false;   
begin
  for j := 0 to ParamCount do
    begin
    MsgBox('param'+ParamStr(j), mbInformation, MB_OK);
      if ParamStr(j)='/verysilent'   then
        isVerySilent := true;

    end; 
  if isVerySilent then begin
    Log ('VerySilent')
  end else
    Log ('not VerySilent');
end;
Tom
  • 6,725
  • 24
  • 95
  • 159
  • 3
    In what *"this one works better"* ? If you are talking about iteration from 0, then note, that on `ParamStr(0)` is the application file name, so there's no need to iterate there. Also, the other version uses `CompareText` which is not case sensitive (yours wouldn't work if the user passes e.g. `/VerySilent`). And finally (but that's what the other version is missing as well) is that you can `Break` the loop when you find the searched parameter. – TLama Oct 15 '14 at 08:42