实际存在时找不到系统文件 [英] Could not find system file when it actually exists

查看:199
本文介绍了实际存在时找不到系统文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实际存在的时候找不到系统文件 - c:\windows\system32\alg.exe。

Could not find system file when it actually exists - "c:\windows\system32\alg.exe".

我已经从Win 7 x86到x64最近,当我在x86我没有任何问题,尝试Delphi 7& XE2。

I've moved from Win 7 x86 to x64 recently and when I was on x86 I had no problem with this, tried Delphi 7 & XE2.

我正在使用的代码:

if FileExists('c:\windows\system32\alg.exe') then
  ShowMessage('fe') else ShowMessage('fne');

试图拥有管理员权限的文件+我的应用程序 - 同样的问题。

Tried to take ownership of a file + my app with admin privilegies - same issue.

查看是否x64 ..

Guys, to check if x64..

function IsWow64Process(Handle:THandle; var IsWow64 : BOOL) : BOOL; stdcall; external 'kernel32.dll';

function IS64 : Boolean;
var
 xIS64 : Bool;
begin
 if IsWow64Process(GetCurrentProcess, xIS64) then
  Result := xIS64 else RaiseLastOSError;
end;


推荐答案

这是因为 WOW64文件系统重定向 ,如果您想要访问本机system32目录的32位应用程序,则必须使用 Wow64DisableWow64FsRedirection 功能或 Sysnative 别名。

尝试此样本

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows;

Function Wow64DisableWow64FsRedirection(Var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
  External 'Kernel32.dll' Name 'Wow64DisableWow64FsRedirection';
Function Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
  External 'Kernel32.dll' Name 'Wow64EnableWow64FsRedirection';

Var
  Wow64FsEnableRedirection: LongBool;
begin
 try
    if Wow64DisableWow64FsRedirection(Wow64FsEnableRedirection) then
    begin
      if FileExists('c:\windows\system32\alg.exe') then
       Writeln('fe')
      else
       Writeln('fne');

      if not Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection) then
       RaiseLastOSError;
    end
    else
    RaiseLastOSError;
 except
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;

end.
end.

此外,检查MSDN文档是否有此主题。

Additionally check the MSDN documentation for this topic.


应用程序可以使用
Wow64DisableWow64FsRedirection,Wow64EnableWow64FsRedirection和
Wow64RevertWow64FsRedirection函数来控制WOW64文件系统重定向器。禁用文件系统
重定向会影响调用
线程执行的所有文件操作,因此只有在需要单个
CreateFile调用并且在函数$ b后立即重新启用时才应该禁用它$ b返回。禁用文件系统重定向更长时间可以
阻止32位应用程序加载系统DLL,导致
应用程序失败。

Applications can control the WOW64 file system redirector using the Wow64DisableWow64FsRedirection, Wow64EnableWow64FsRedirection, and Wow64RevertWow64FsRedirection functions. Disabling file system redirection affects all file operations performed by the calling thread, so it should be disabled only when necessary for a single CreateFile call and re-enabled again immediately after the function returns. Disabling file system redirection for longer periods can prevent 32-bit applications from loading system DLLs, causing the applications to fail.



Sysnative



Sysnative


32位应用程序可以通过
访问本机系统目录,替换%windir%\Sysnative对于%windir%\System32。 WOW64
将Sysnative识别为特殊别名,用于指示文件
系统不应重定向该访问。这种机制是灵活的,
易于使用,因此,推荐的机制绕过文件
系统重定向。请注意,64位应用程序不能使用
Sysnative别名,因为它不是真正的虚拟目录。

32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.



{$APPTYPE CONSOLE}

{$R *.res}

uses
  SysUtils,
  Windows;

begin
 try
    if FileExists('c:\windows\SysNative\alg.exe') then
     Writeln('fe')
    else
     Writeln('fne');
 except
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;

end.

这篇关于实际存在时找不到系统文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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