Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

inno-setup

It seems, that some files which I wanna check with FileExists() can never be found even if they are there, others are found every time.

If I put the file "driver.sys" into the "C:\Windows\System32\drivers\" directory, it would never be found (FileExists is false every time i call the function). If I move the file into the Windows root "C:\Windows\" it is found.

This doesn't work (while the file is definitely in the folder 'C:\Windows\System32\drivers\'):

function isNotDriverInstalled(): Boolean;
begin
  if (FileExists('C:\Windows\System32\drivers\driver.sys')) then begin
    Log('File exists');
    Result := False;
  end else begin
    Log('File doesn''t exist');
    Result := True;
  end;
end;

This works (while the file is in the folder 'C:\Windows\'):

function isNotDriverInstalled(): Boolean;
begin
  if (FileExists('C:\Windows\driver.sys')) then begin
    Log('File exists');
    Result := False;
  end else begin
    Log('File doesn''t exist');
    Result := True;
  end;
end;

Btw: I am using Windows 7, 64 Bit.

Has anybody experienced such a case before? Any suggestions?

Thx in advance!

like image 550
pianissimo Avatar asked Feb 19 '23 06:02

pianissimo


1 Answers

Your System32 directory is mapped to the SysNative path due to File System Redirector, so as you can see, hardcoding of such directory path is not that easy. Better use one of built-in constants listed below:

1. The {sys} constant:

You can use the {sys} constant, but make sure you allowed the setup to run in 64-bit mode. For more information about how to do it, see the ArchitecturesInstallIn64BitMode directive reference and be sure to read the 64-bit Installation Limitations topic.

From the {sys} constant reference:

The system's System32 directory. For example: If you used {sys}\CTL3D32.DLL on an entry and the system's Windows System directory is "C:\WINDOWS\SYSTEM", Setup or Uninstall will translate it to "C:\WINDOWS\SYSTEM\CTL3D32.DLL".

On 64-bit Windows, by default, the System32 path returned by this constant maps to the directory containing 32-bit system files, just like on 32-bit Windows. (This can be overridden by enabling 64-bit mode.)

Here is how you can use it:

if FileExists(ExpandConstant('{sys}\drivers\driver.sys')) then
  Log('File exists');

2. The {syswow64} constant:

From the {syswow64} constant reference:

On 64-bit Windows, the system's SysWOW64 directory, typically "C:\WINDOWS\SysWOW64". This is the actual directory in which 32-bit system files reside. On 32-bit Windows, 32-bit system files reside in "System32" or "System", not in a separate SysWOW64 directory, so this constant will resolve to the same directory as {sys} if used there.

Do not use this constant unless you have a specific need to obtain the name of the actual directory in which 32-bit system files reside. Gratuitously using {syswow64} in places where {sys} will suffice may cause problems. (See the documentation for the [Files] section's sharedfile flag for one example.)

Here is how you can use it:

if FileExists(ExpandConstant('{syswow64}\drivers\driver.sys')) then
  Log('File exists');
like image 142
TLama Avatar answered Feb 20 '23 20:02

TLama