Install log file is missing

11,939

Solution 1

You can specify a path to the log file by the setup /LOG="filename" command line parameter. So to log e.g. to the C:\FileName.log file run your setup this way:

Setup.exe /LOG="C:\FileName.log"

If you don't specify the above command line parameter, the log will be saved to the temporary directory into the file with the following name pattern:

Setup Log YYYY-MM-DD #NNN.txt

Where:

YYYY - current system time year
MM - current system time month
DD - current system time day
NNN - number unique for each day starting from 1

Solution 2

It's like TLama describes, if you don't state the logfile's destination as a command line parameter then it will land up in the temp folder. Below is some code that I use for copying the logfile at the DeinitializSetup event for Installer and for the Uninstaller's DeinitializUninstall event.

Installer

After instalation the logfile is copied from the temp folder and placed it into one of choice. It handles some cases of pre-mature termination.

function MoveLogfileToLogDir():boolean;
var
  logfilepathname, logfilename, newfilepathname: string;
begin
  logfilepathname := expandconstant('{log}');

  //If logfile is disabled then logfilepathname is empty
  if logfilepathname = '' then begin
     result := false;
     exit;
  end;

  logfilename := ExtractFileName(logfilepathname);
  try
    //Get the install path by first checking for existing installation thereafter by GUI settings
    if IsAppInstalled then
       newfilepathname := GetInstalledPath + 'Log\Installer\'
    else
       newfilepathname := expandconstant('{app}\Log\Installer\');
  except
    //This exception is raised if {app} is invalid i.e. if canceled is pressed on the Welcome page
        try
          newfilepathname := WizardDirValue + '\Log\Installer\'; 
        except
          //This exception is raised if WizardDirValue i s invalid i.e. if canceled is pressed on the Mutex check message dialog.
          result := false;
        end;
  end;  
  result := ForceDirectories(newfilepathname); //Make sure the destination path exists.
  newfilepathname := newfilepathname + logfilename; //Add filename

  //if copy successful then delete logfilepathname 
  result := filecopy(logfilepathname, newfilepathname, false);

  if result then
     result := DeleteFile(logfilepathname);
end;

//Called just before Setup terminates. Note that this function is called even if the user exits Setup before anything is installed.
procedure DeinitializeSetup();
begin
  MoveLogfileToLogDir;
end;

Uninstaller

Logging in the Uninstaller is activated by passing "/Log" command line parameter to uninstall.exe. Append this to uninstaller's path in the registry. Cavet: this method will only work if uninstalled from Control Panel (i.e. it won't work if uninstall.exe is excecuted directly)

function EnableUninstallerLogging():boolean;
var Key : string;          //Registry path to details about the current installation (uninstall info)
    Value : string;
begin

  //If logfile is disabled then logfilepathname is empty
  if expandconstant('{log}') = '' then begin
     result := false;
     exit;
  end;

  Key := GetAppUninstallRegKey;
  Value := 'UninstallString';
  if RegValueExists(HKEY_LOCAL_MACHINE, Key, Value) then
     result := RegWriteStringValue(HKEY_LOCAL_MACHINE, Key, Value, ExpandConstant('"{uninstallexe}" /Log'));
end;


procedure CurStepChanged(CurStep: TSetupStep);
begin
   case CurStep of
         ssInstall : ;
     ssPostInstall : begin
                       //Enable logging during uninstall by adding command line parameter "/Log" to the uninstaller's  reg-path 
                       EnableUninstallerLogging;
                     end;
            ssDone : ;
  end;
end;

//Called just before Uninstaller terminates.
procedure DeinitializeUninstall();
begin
  MoveLogfileToLogDir;
end;

Generic Functions

Some common functions I use in the sample code above:

function GetAppID():string;
begin
  result := ExpandConstant('{#SetupSetting("AppID")}');     
end;

function GetAppUninstallRegKey():string;
begin
  result := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\' + GetAppID + '_is1'); //Get the Uninstall search path from the Registry
end;

function IsAppInstalled():boolean;
var Key : string;          //Registry path to details about the current installation (uninstall info)
begin                            
  Key := GetAppUninstallRegKey;
  result := RegValueExists(HKEY_LOCAL_MACHINE, Key, 'UninstallString');
end;

//Return the install path used by the existing installation.
function GetInstalledPath():string;
var Key : string;
begin
  Key := GetAppUninstallRegKey;
  RegQueryStringValue(HKEY_LOCAL_MACHINE, Key, 'InstallLocation', result);
end;                                                                      
Share:
11,939

Related videos on Youtube

CJBS
Author by

CJBS

https://www.linkedin.com/in/christopherscholten/ https://social.msdn.microsoft.com/profile/%D1%81%D1%92r%CE%90s%CF%84%CF%83%CF%81h%CE%BEr%20sc%D1%9B%CE%B4l%CF%84%CE%BE%CE%B7/

Updated on June 04, 2022

Comments

  • CJBS
    CJBS almost 2 years

    I made a script including this:

    [Setup]
    
    SetupLogging=yes
    

    But I can't find the log file. It seems like it was not created. Where could it be?

    Is that possible to specify where I want to place it?

  • Admin
    Admin over 10 years
    Thank you. Can I specify where to place the log from the script itself? I prefer not to ask the users to use "/LOG"
  • TLama
    TLama over 10 years
    I've read the above information from source code. No, there is no such option. The only place where the LogFilename variable is filled is here. Then it's checked if it's value is empty (that's when the /LOG="filename" cmd line parameter is not specified) or not. Depending on that is created log file by the above rules. You can only get the log file name from the {log} constant.
  • Jason
    Jason almost 9 years
    Thanks for that. I had difficulties finding the file! It was in C:\Users\<User's name>\AppData\Local\Temp.
  • Mark Berry
    Mark Berry over 8 years
    Windows has several locations for storing temp files, but as @Jason points out in a comment on another answer, Inno uses C:\Users\<User's name>\AppData\Local\Temp, also known as %temp%.