【转】64位WIN7下读取系统目录下文件失败的解决办法

 

转自:http://www.delphipraxis.net/86723-datei-ausfuehren-unter-windows-64-bit-2.html

原因见:http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx

 1  Function ChangeFSRedirection(bDisable: Boolean): Boolean;
 2 
 3  Type TWow64DisableWow64FsRedirection = Function(Var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
 4       TWow64EnableWow64FsRedirection = Function(var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
 5   Var
 6     hHandle: THandle;
 7     Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
 8     Wow64EnableWow64FsRedirection: TWow64EnableWow64FsRedirection;
 9     Wow64FsEnableRedirection:      LongBool;
10 begin
11 Result := true;
12 if not Is64Bit then exit; // Kein 64-Bit-Win? 
13  try
14     hHandle := GetModuleHandle('kernel32.dll');
15     @Wow64EnableWow64FsRedirection := GetProcAddress(hHandle, 'Wow64EnableWow64FsRedirection');
16     @Wow64DisableWow64FsRedirection := GetProcAddress(hHandle, 'Wow64DisableWow64FsRedirection');
17     if bDisAble then begin
18      If ((hHandle <> 0) and (@Wow64EnableWow64FsRedirection <> nil) and (@Wow64DisableWow64FsRedirection <> nil)) Then
19       Wow64DisableWow64FsRedirection(Wow64FsEnableRedirection);
20     end;
21     if not bDisAble then
22     If ((hHandle <> 0) and (@Wow64EnableWow64FsRedirection <> nil) and (@Wow64DisableWow64FsRedirection <> nil)) Then
23       Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection);
24  Except Result := false;
25  end;
26 
27 end;

 

调用:

1 ChangeFSRedirection(true);
2 OpenFile('C:\Windows\system32\einedatei.txt');
3 ChangeFSRedirection(false);

 

posted @ 2012-03-30 19:19  流星无语  阅读(765)  评论(0编辑  收藏  举报