我做了一个包含这个的脚本:
[Setup]
SetupLogging=yes
但我找不到日志文件。好像它没有创建。 它可能在哪里?
可以指定我想放置它的位置吗?
谢谢
答案 0 :(得分:8)
您可以通过setup /LOG="filename"
命令行参数指定日志文件的路径。所以要记录,例如到C:\FileName.log
文件以这种方式运行您的设置:
Setup.exe /LOG="C:\FileName.log"
如果未指定上述命令行参数,则日志将使用以下名称模式保存到临时目录中:
Setup Log YYYY-MM-DD #NNN.txt
其中:
YYYY - current system time year
MM - current system time month
DD - current system time day
NNN - number unique for each day starting from 1
答案 1 :(得分:7)
就像TLama描述的那样,如果你没有将日志文件的目的地说明为命令行参数,那么它将在临时文件夹中登陆。下面是一些代码,用于在安装程序的DeinitializSetup事件和Uninstaller的DeinitializUninstall事件中复制日志文件。
<强>安装强>
安装后,将从temp文件夹中复制日志文件并将其放入选择之一。它处理了一些预成熟终止的情况。
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;
<强>卸载程序强>
通过将“/ Log”命令行参数传递给uninstall.exe来激活登录卸载程序。将其附加到注册表中的卸载程序路径。警告:此方法仅在从控制面板卸载时才有效(即如果uninstall.exe直接执行则无效)
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;
通用功能
我在上面的示例代码中使用的一些常用函数:
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;