Inno Setup File存在无法找到现有文件

EaranMaleasi

在我的脚本中,我正在检查目录和该目录中是否存在两个文件。当第一个返回正确的值时,第二个检查则没有。我已多次检查这些文件是否存在于指定目录中,但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总是告诉我它不在那里。虚拟环境是否混乱?这是怎么回事

马丁·普里克里(Martin Prikryl)

要调试该问题,请尝试添加以下代码。然后检查安装程序的日志文件和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/FindNextGetFileAttributes因此,这是找出导致问题的原因。


我的疯狂猜测是目标计算机是64位的,文件系统重定向由于某种原因而跳入。

EnableFsRedirection在致电之前,尝试使用来禁用重定向FileExists

EnableFsRedirection(False);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Inno Setup File存在无法找到现有文件

来自分类Dev

Inno Setup,检测参数文件是否存在?

来自分类Dev

Inno Setup:{code:...}无法用于OutputBaseFilename吗?

来自分类Dev

无法从[代码]调用Inno Setup ParseVersion

来自分类Dev

Inno Setup查找子文件夹

来自分类Dev

Inno Setup –更新之前压缩本地文件

来自分类Dev

在Inno Setup中复制隐藏文件

来自分类Dev

Inno Setup拒绝设置某些文件的权限

来自分类Dev

在Inno Setup中创建ZIP文件

来自分类Dev

提供Inno Setup下载功能的文件大小

来自分类Dev

Inno Setup:从测试文件中删除空行

来自分类Dev

Inno Setup Compiler:如何修改文件内容

来自分类Dev

Inno Setup查找子文件夹

来自分类Dev

Inno Setup 从输入用户解压文件

来自分类Dev

Inno setup 只删除文件夹

来自分类Dev

Inno Setup:覆盖现有安装或显示目录提示

来自分类Dev

如何使用通配符测试Inno Setup中是否存在文件

来自分类Dev

Inno Setup将文件和文件夹复制到现有的Zip文件

来自分类Dev

无法从PowerShell脚本写入默认的Inno Setup日志文件

来自分类Dev

Inno Setup无法处理带有空格的源路径

来自分类Dev

使用带有Signonce标志的Inno Setup签名文件

来自分类Dev

Inno Setup:列出目录中的所有文件名

来自分类Dev

使用带有Signonce标志的Inno Setup签名文件

来自分类Dev

Inno Setup无法使用AppVeyor上的遮罩找到图像文件

来自分类Dev

Inno Setup语法-OR,AND

来自分类Dev

Inno Setup中的TTreeView

来自分类Dev

存在的所有子目录中的inno-setup更新文件

来自分类Dev

Inno Setup:Exec无法读取字符串?

来自分类Dev

Inno Setup执行功能无法完全正常运行