harish sai
harish sai

Reputation: 31

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

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;

Upvotes: 1

Views: 426

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202118

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;

Upvotes: 1

Related Questions