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?
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;