如何登录Inno Setup安装?

sas*_*alm 18 logging inno-setup

Inno Setup具有命令行参数/LOG="filename".我可以在Inno Setup脚本中指定日志文件名,因此我可以在以后的错误报告中包含它吗?

mir*_*eil 20

您可以设置SetupLogging选项(SetupLogging=yes),然后将以下代码集成到脚本中以将日志复制到某处.

procedure CurStepChanged(CurStep: TSetupStep);
var
  logfilepathname, logfilename, newfilepathname: string;
begin
  logfilepathname := ExpandConstant('{log}');
  logfilename := ExtractFileName(logfilepathname);
  newfilepathname := ExpandConstant('{app}\') + logfilename;

  if CurStep = ssDone then
  begin
    FileCopy(logfilepathname, newfilepathname, false);
  end;
end; 
Run Code Online (Sandbox Code Playgroud)

  • 您是否真的认为有必要在每个设置步骤中反复重新计算路径和文件名?为什么不把它移到`if CurStep = ssDone then-block? (8认同)
  • +1 Mittheil!我已经使用过您的提示但是请在DeinitializeSetup中调用.然后,即使用户在安装任何内容之前退出安装程序,也会复制日志. (8认同)

小智 12

根据Lars的评论,我使用了该DeinitializeSetup()过程,但我还更改了新文件路径,使用{src}常量将日志文件复制到运行安装程序的目录而不是{app}常量,如果用户取消,可能会/可能不会创建安装:

// Called just before Setup terminates. Note that this function is called even if the user exits Setup before anything is installed.
procedure DeinitializeSetup();
var
  logfilepathname, logfilename, newfilepathname: string;
begin
  logfilepathname := ExpandConstant('{log}');
  logfilename := ExtractFileName(logfilepathname);
  // Set the new target path as the directory where the installer is being run from
  newfilepathname := ExpandConstant('{src}\') + logfilename;

  FileCopy(logfilepathname, newfilepathname, false);
end; 
Run Code Online (Sandbox Code Playgroud)