Inno Setup:检查32位System32(系统)文件夹中是否存在文件 [英] Inno Setup: Checking existence of a file in 32-bit System32 (Sysnative) folder

查看:499
本文介绍了Inno Setup:检查32位System32(系统)文件夹中是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在System32\Drivers文件夹中有一个名为gpiotom.sys的sys文件(自定义sys文件).我的应用程序严格仅与32位兼容,因此我的安装程序以32位模式运行.我的脚本需要查找此sys文件是否存在.

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.

我使用了下面的文章中介绍的FileExists函数,但是它仅适用于64位应用程序,因此无法正常工作:

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()找不到每个文件

有什么方法可以确定我的sys文件是否以32位模式存在?

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

这是我用Pascal脚本语言编写的代码段:

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;

推荐答案

通常,我认为在64位模式下为32位应用程序运行安装程序没有任何问题.只要确保在必要时使用32位路径即可,例如:

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


无论如何,如果要坚持使用32位模式,则可以使用 EnableFsRedirection函数禁用WOW64文件系统重定向.


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

使用此功能,您可以替代FileExists:

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;

这篇关于Inno Setup:检查32位System32(系统)文件夹中是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆