Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi FileExists und Vista 64 Bit funktioniert nicht ? (https://www.delphipraxis.net/127253-fileexists-und-vista-64-bit-funktioniert-nicht.html)

TKC 9. Jan 2009 22:26


FileExists und Vista 64 Bit funktioniert nicht ?
 
Hallo,

ich teste gerade Delphi 2009 auf Vista 64 Bit und habe ein kleines Problem festgestellt.
Delphi und Vista sind auf dem aktuellen Stand.

Wenn ich die Funktion FileExists() in einem Windows Ordner benutze gibt sie immer False zurrück.

z.B.:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin

  if FileExists('C:\windows\system32\drivers\kbdclass.sys') then
    ShowMessage('ok');

end;
Die Datei existiert natürlich !

In anderen Ordnern funktioniert es normal.

Was ist da das Problem und wie umgehe ich das ?

jbg 9. Jan 2009 22:33

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Zitat:

Zitat von TKC
Die Datei existiert natürlich !

Probiere es mal mit dem echten "System32" Ordner: C:\Windows\SysWOW64

TKC 9. Jan 2009 22:36

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Hilft leider nichts ... gleiches Problem.

Meflin 9. Jan 2009 22:38

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Hatte heute ein ganz ähnliches Phänomen: Ich hätte einen Treiber in einem Open-Dialog auswählen sollen - aber da waren keine, obwohl natürlich im Verzeichnis vorhanden :gruebel:

TKC 10. Jan 2009 03:57

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
So ... ich habe es jetzt mal so gelöst ...

Delphi-Quellcode:
function FileExists64NoRedirection(Filename: string): Boolean;
type
  TWow64DisableWow64FsRedirection = function(var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
  TWow64RevertWow64FsRedirection = function(var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;

var
  hHandle: THandle;
  Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
  Wow64RevertWow64FsRedirection: TWow64RevertWow64FsRedirection;
  Wow64FsEnableRedirection: LongBool;
  Is64BitWin: boolean;

begin
  Is64BitWin := False;
  Wow64DisableWow64FsRedirection := nil;
  Wow64RevertWow64FsRedirection := nil;

  try
    hHandle := GetModuleHandle('kernel32.dll');
    @Wow64RevertWow64FsRedirection := GetProcAddress(hHandle, 'Wow64RevertWow64FsRedirection');
    @Wow64DisableWow64FsRedirection := GetProcAddress(hHandle, 'Wow64DisableWow64FsRedirection');


    if ((hHandle <> 0) and (@Wow64RevertWow64FsRedirection <> nil) and (@Wow64DisableWow64FsRedirection <> nil)) then
      Is64BitWin := True;

  except
    Is64BitWin := False;
  end;

  if Is64BitWin then
    begin
      Wow64DisableWow64FsRedirection(Wow64FsEnableRedirection);
      Result := FileExists(Filename);
      Wow64RevertWow64FsRedirection(Wow64FsEnableRedirection);
    end
  else
    Result := FileExists(Filename);

end;
Es liegt wohl an der "File system redirection" von 64 Bit Systemen, die im System32 Ordner und anderen aktiv ist.

Aber irgendwie denke ich, das CG das mal etwas anpassen sollte.
Ich bin noch für andere Lösungen offen.

jfheins 10. Jan 2009 09:48

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Vll. das hier:
Zitat:

Starting with Windows Vista, 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.
http://msdn.microsoft.com/en-us/libr...87(VS.85).aspx ;)

mjustin 10. Jan 2009 11:09

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Zitat:

Zitat von TKC
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin

  if FileExists('C:\windows\system32\drivers\kbdclass.sys') then
    ShowMessage('ok');

end;

Mit GetSystemDirectory (oder GetWindowsSystemFolder aus der JCL) sollte sich das Windows System Verzeichnis ermitteln lassen, ich habe leider kein Vista 64 zum Testen hier.

Dezipaitor 10. Jan 2009 13:06

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Vista leitet diesen Zugriff auf das Wow64 (oder so ähnlich) Verzeichnis um. Darin sind die 32bit Dateien.

Meflin 10. Jan 2009 13:12

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Zitat:

Zitat von Dezipaitor
Vista leitet diesen Zugriff auf das Wow64 (oder so ähnlich) Verzeichnis um. Darin sind die 32bit Dateien.

Auch wenns jetz nix mit dem Thema zu tun hat: Das sollte aber dann doch auch aus einem Öffnen-Dialog heraus funktionieren - der wurde bie mir scheinbar nicht umgeleitet?!

Dezipaitor 10. Jan 2009 14:27

Re: FileExists und Vista 64 Bit funktioniert nicht ?
 
Vielleicht schaltet der Dialog das Umleiten aus? Oder hast du es ausgeschaltet? Oder du wurdest einfach reingelegt? :-D
Erzeuge doch mal mit dem Explorer eine Datei im echten 64bit Ordner und versuche sie zu finden mit nem 32bit Prog.


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:49 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz