在我的脚本中,我正在检查目录和该目录中是否存在两个文件。当第一个返回正确的值时,第二个检查则没有。我已多次检查这些文件是否存在于指定目录中,但Inno Setup会始终告诉我它们不存在。这是在虚拟Windows Server上发生的,无法在我的本地计算机上复制。在那里,它总是返回正确的值。
UpdatePath := ExpandConstant('{app}');
if DirExists(UpdatePath) then begin
ExePath := UpdatePath+'\Application.exe';
ConfigFilePath := UpdatePath+'\Application.exe.config';
if FileExists(ExePath) and FileExists(ConfigFilePath) then begin //this one returns incorrect values
//Do Stuff
end else begin
MsgBox(FmtMessage(CustomMessage('DirPageFileNotFound'), [ExePath, ConfigFilePath]),mbInformation,MB_OK);
Result := False;
end;
end else begin
MsgBox(FmtMessage(CustomMessage('DirPageDirectoryNotFound'), [UpdatePath]),mbInformation,MB_OK);
Result := False;
end;
如您所见,我正在检查一个可执行文件,双击该可执行文件也可以执行。它在那里,但是Inno Setup总是告诉我它不在那里。虚拟环境是否混乱?这是怎么回事
要调试该问题,请尝试添加以下代码。然后检查安装程序的日志文件和dir
命令的输出:
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
function GetFileAttributes(lpFileName: string): DWORD;
external 'GetFileAttributes{#AW}@kernel32.dll stdcall';
function GetLastError() : LongInt;
external '[email protected] stdcall';
const
INVALID_FILE_ATTRIBUTES = $FFFFFFFF;
procedure ...;
var
UpdatePath: string;
ExePath: string;
FindRec: TFindRec;
Attrs: DWORD;
LastError: LongInt;
ResultCode: Integer;
begin
Log('InitializeWizard');
UpdatePath := ExpandConstant('{app}');
ExePath := UpdatePath+'\Application.exe';
if FileExists(ExePath) then
begin
Log(ExePath + ' exists');
end
else
begin
LastError := GetLastError;
Log(ExePath + ' does not exist - ' +
Format('System Error. Code: %d. %s', [LastError, SysErrorMessage(LastError)]));
end;
if not FindFirst(UpdatePath + '\*', FindRec) then
begin
LastError := GetLastError;
Log(UpdatePath + ' not found - ' +
Format('System Error. Code: %d. %s', [LastError, SysErrorMessage(LastError)]));
end
else
begin
repeat
Log('Found file: ' + FindRec.Name + ' in ' + UpdatePath);
until not FindNext(FindRec);
end;
Attrs := GetFileAttributes(ExePath);
if Attrs <> INVALID_FILE_ATTRIBUTES then
begin
Log(ExePath + ' attributes = ' + IntToStr(Attrs));
end
else
begin
LastError := GetLastError;
Log(Format('Cannot get attributes of ' + ExePath + ': System Error. Code: %d. %s', [
LastError, SysErrorMessage(LastError)]));
end;
Exec(ExpandConstant('{cmd}'), '/k dir "' + UpdatePath + '"', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode);
end;
在FileExists
内部使用FindFirst
/FindNext
和GetFileAttributes
。因此,这是找出导致问题的原因。
我的疯狂猜测是目标计算机是64位的,文件系统重定向由于某种原因而跳入。
EnableFsRedirection
在致电之前,尝试使用来禁用重定向FileExists
:
EnableFsRedirection(False);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句