5

Setting SetupLogging=yes creates the a file:

%TEMP%\Setup Log YYYY-MM-DD #NNN.txt

Is there any way to specify the name of the file? Note that I know I can rename it using FileCopy at the end of the installation (How can I log Inno Setup installations?), but I simply want to specify the name of the file at the outset, much like can be done with the switch /log=%TEMP%\ProductInstall.log. Is this possible?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Robert Wigley
  • 1,917
  • 22
  • 42

2 Answers2

4

No. It's not possible. The log file name format for the SetupLogging is hard-coded.

All you can do it to check in InitializeSetup, if /LOG= was specified on command-line and if not, re-spawn the installer with the /LOG=.

Though it's somewhat an overkill.

function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
  lpParameters: string; lpDirectory: string; nShowCmd: Integer): THandle;
  external 'ShellExecuteW@shell32.dll stdcall';

function InitializeSetup(): Boolean;
var
  HasLog: Boolean;
  Params: string;
  I: Integer;
  S: string;
  RetVal: Integer;
begin
  HasLog := False;
  Params := '';
  for I := 1 to ParamCount do
  begin
    S := ParamStr(I);
    if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then
    begin
      HasLog := True;
      break;
    end;
    // Do not pass our /SL5 switch
    // This should not be needed since Inno Setup 6.2,
    // see https://groups.google.com/g/innosetup/c/pDSbgD8nbxI
    if CompareText(Copy(S, 1, 5), '/SL5=') = 0 then
    begin
      Params := Params + AddQuotes(S) + ' ';
    end;
  end;

  Result := True;
  if HasLog then
  begin
    Log('Log specified, continuing.');
  end
    else
  begin
    // add selected language, so that user is not prompted again
    Params := Params + ' /LANG=' + ActiveLanguage;
    // force logging
    Params :=
      Params + ' /LOG="' + ExpandConstant('{%TEMP}\ProductInstall.log') + '"';
    Log(Format('Log file not specified, restarting setup with [%s]', [Params]));
    RetVal :=
      ShellExecute(0, '', ExpandConstant('{srcexe}'), Params, '', SW_SHOW);
    Log(Format('Restarting setup returned [%d]', [RetVal]));
    if RetVal > 32 then
    begin
      Log('Restart with logging succeeded, aborting this instance');
      Result := False;
    end
      else
    begin
      Log(Format('Restarting with logging failed [%s], keeping this instance', [
        SysErrorMessage(RetVal)]));
    end;
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Martin, thanks for confirming what I suspected and for suggesting a workaround, although, as you say, it is a bit overkill. I think I will go with renaming the file at the end of the install instead. – Robert Wigley Mar 04 '16 at 19:34
1

Here's what I came up with to rename the log after setup completes. This is a bit tricky because you can't rename it while Inno Setup's still using it, but using start and timeout I was able to spin off a separate cmd process that waits a second, then does the rename.

[Run]
; Rename the log file to My_setup_log.txt.
Filename: "{cmd}"; WorkingDir: "{%TEMP}"; Parameters: "/d /c start "" "" /b cmd /d /c ""timeout 1 >NUL & del My_setup_log.txt 2>NUL & ren """"""{log}"""""" My_setup_log.txt"""; Flags: runhidden

As you can see, getting the proper number of quotes to surround the filenames in the quoted cmd argument requires six quotes in the Inno Setup command. If you want spaces in your renamed log file, put the six quotes on either side of it too. Yes, this would mean the string will end with nine consecutive quote marks!

kindall
  • 178,883
  • 35
  • 278
  • 309