Inno Setup: Checking existence of a file in 32-bit System32 (Sysnative) folder

柔情痞子 提交于 2019-12-23 02:29:08

问题


I have a sys file in the System32\Drivers folder called gpiotom.sys (custom sys file). My my application is strictly 32-bit compatible only, so my installer runs in 32-bit mode. My script needs to find if this sys file exists or not.

I used the FileExists function explained on the below post but it does not work since it only works for 64-bit application only:

InnoSetup (Pascal): FileExists() doesn't find every file

Is there any way I can find if my sys file exists or not in a 32-bit mode?

Here is my code snippet in Pascal Script language:

function Is_Present() : Boolean;
begin
  Result := False;
  if FileExists('{sys}\driver\gpiotom.sys') then
  begin
    Log('File exists');
    Result := True;
  end;
end;

回答1:


In general, I do not think there is any problem running an installer for 32-bit application in 64-bit mode. Just make sure you use 32-bit paths where necessary, like:

[Setup]
DefaultDirName={pf32}\My Program

Anyway, if you want to stick with 32-bit mode, you can use EnableFsRedirection function to disable WOW64 file system redirection.

With use of this function, you can implement a replacement for FileExists:

function System32FileExists(FileName: string): Boolean;
var
  OldState: Boolean;
begin
  if IsWin64 then
  begin
    Log('64-bit system');
    OldState := EnableFsRedirection(False);
    if OldState then Log('Disabled WOW64 file system redirection');
    try
      Result := FileExists(FileName);
    finally
      EnableFsRedirection(OldState);
      if OldState then Log('Resumed WOW64 file system redirection');
    end;
  end
    else
  begin
    Log('32-bit system');
    Result := FileExists(FileName);
  end;

  if Result then
    Log(Format('File %s exists', [FileName]))
  else
    Log(Format('File %s does not exists', [FileName]));
end;


来源:https://stackoverflow.com/questions/49501554/inno-setup-checking-existence-of-a-file-in-32-bit-system32-sysnative-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!