设置SetupLogging=yes
将创建一个文件:
%TEMP%\ Setup日志YYYY-MM-DD#NNN.txt
有什么方法可以指定文件名?请注意,我知道我可以在安装结束(How can I log Inno Setup installations?)时使用FileCopy
重命名它,但是我只是想一开始就指定文件名,就像使用开关/log=%TEMP%\ProductInstall.log
一样。 。这可能吗?
最佳答案
不行,不可能SetupLogging
的日志文件名格式是硬编码的。
您可以执行所有操作来检入InitializeSetup
,如果在命令行上指定了/LOG=
,如果未指定,请使用/LOG=
重新生成安装程序。
虽然有点过分。
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 }
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;