Recent

Author Topic: [Solved] Problems with FileExists on Win7 x64  (Read 22527 times)

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
[Solved] Problems with FileExists on Win7 x64
« on: April 06, 2013, 04:04:07 pm »
Hello form Argentina! My first message and sorry if errors in translation.  O:-) I speak spanish.

I have an stupid problem with FileExists.

Content of the dir: C:\Windows\System32\Macromed\Flash\

Code: [Select]
C:\Windows\System32\Macromed\Flash\activex.vch
C:\Windows\System32\Macromed\Flash\Flash64_11_6_602_180.ocx
C:\Windows\System32\Macromed\Flash\FlashInstall.log
C:\Windows\System32\Macromed\Flash\FlashUtil64_11_6_602_180_ActiveX.dll
C:\Windows\System32\Macromed\Flash\FlashUtil64_11_6_602_180_ActiveX.exe
C:\Windows\System32\Macromed\Flash\FlashUtil64_11_6_602_180_Plugin.exe
C:\Windows\System32\Macromed\Flash\NPSWF64_11_6_602_180.dll
C:\Windows\System32\Macromed\Flash\plugin.vch


Code: [Select]
FileExists('C:\Windows\System32\Macromed\Flash\FlashUtil64_11_6_602_180_Plugin.exe');  //--> False

FileExistsUTF8('C:\Windows\System32\Macromed\Flash\FlashUtil64_11_6_602_180_Plugin.exe'); //--> False

FileExists('C:\Windows\System32\Macromed\Flash\test_file_name.txt'); //--> False

//but the following works

DirectoryExists('C:\Windows\System32\Macromed\Flash'); //--> True

FileExists('C:\Windows\System32\Macromed\Flash\FlashInstall.log'); //--> True

FileExists('C:\test_file_name.txt'); //--> True

FileExists('C:\Windows\SysWOW64\Macromed\Flash\FlashUtil32_11_6_602_180_Plugin.exe'); //--> True


Anyone else did this happen?

-------

Lazarus v1.0.8 (2013-03-17) on Windows 7 x64 Home Premium .
« Last Edit: April 07, 2013, 01:15:38 am by u2o »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Problems with FileExists
« Reply #1 on: April 06, 2013, 04:14:08 pm »
What other SW you have running? Sometimes they have an effect :
  http://bugs.freepascal.org/view.php?id=24162

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Problems with FileExists
« Reply #2 on: April 06, 2013, 04:19:35 pm »
What other SW you have running? Sometimes they have an effect :
  http://bugs.freepascal.org/view.php?id=24162
Juha

Hi Juha!

SVN: 40573
installer: lazarus-1.0.8-fpc-2.6.2-win32.exe


----

Edited -> The same result, building the project on a Windows 7 x86 Home premium. With the same version of lazarus.
« Last Edit: April 06, 2013, 04:22:17 pm by u2o »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Problems with FileExists
« Reply #3 on: April 06, 2013, 04:34:51 pm »
SVN: 40573
version: x86
installer: lazarus-1.0.8-fpc-2.6.2-win32.exe

Thanks. That is also important info but I was asking about other SW running.
Qué otras programas estan corriendo en tu máguina?
The bug report is about DoubleCommander effect.
Shared Samba drives is another known issue, but it does not affect you because your files are in local C:.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Problems with FileExists
« Reply #4 on: April 06, 2013, 04:41:13 pm »
Oh sorry...

No special software, Mozilla Thunderbird, Locate32, KeePass, Google Chrome, Nod32 Antivirus (disabled), Aimp 3, DaemonTools, Zentimo xStorage Manager... Internet connection but nothing more.

I' will try with all software closed...


---- Edited ----

With all application (written before)  closed, the same result...

---- Edited ----

Sorry for the question in a wrong place... If you can please move to the correct place...
« Last Edit: April 06, 2013, 04:51:51 pm by u2o »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Problems with FileExists
« Reply #5 on: April 06, 2013, 04:54:43 pm »
I can't test it myself, but I guess it's relative to the fact that you are coding for a 32 bits application (i.e. i386-win32).

Would it be for win64, you've got probably the contrary.

See these topics (for instance), concerning C:\Windows\SysWOW64 and C:\Windows\System32:

http://stackoverflow.com/questions/949959/why-do-64-bit-dlls-go-to-system32-and-32-bit-dlls-to-syswow64-on-64-bit-windows

http://blogs.sepago.de/e/helge/2008/04/20/windows-x64-all-the-same-yet-very-different-part-7
« Last Edit: April 06, 2013, 05:10:03 pm by ChrisF »

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Problems with FileExists
« Reply #6 on: April 06, 2013, 05:21:29 pm »
Ok you not in WinX64. Equally I understand your point.

On Windows x64
The System files 64bits are in C:\Windows\System32
The System files 32bits are in C:\Windows\SysWOW64

Yes.
But my point is other, testing on another file in the same folder of flash, creating the file
C:\Windows\System32\Macromed\Flash\test_file_name.txt

the test result
Code: [Select]
FileExists('C:\Windows\System32\Macromed\Flash\test_file_name.txt'); //--> False
but this works
Code: [Select]
FileExists('C:\Windows\System32\Macromed\Flash\FlashInstall.log'); //--> True

---- Edited ----

It´s very strange. For example I have a project on VB6 and FileExist works fine on this test...
« Last Edit: April 06, 2013, 05:24:18 pm by u2o »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Problems with FileExists
« Reply #7 on: April 06, 2013, 05:23:06 pm »
Same here: GetFileAttributes retruns $FFFFFFFF for these files, while on console Attrib returns either A or AR...
[edit]
And GetLastError returns $02 ("The system cannot find the file specified.")

Bart
« Last Edit: April 06, 2013, 05:30:52 pm by Bart »

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Problems with FileExists
« Reply #8 on: April 06, 2013, 05:26:47 pm »
Could it be a permissions issue?
Creating the files as administrator but checking as local user?
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Problems with FileExists
« Reply #9 on: April 06, 2013, 05:32:50 pm »
Could it be a permissions issue?
Creating the files as administrator but checking as local user?
Ran test as administrator: same results.

Bart

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Problems with FileExists
« Reply #10 on: April 06, 2013, 05:33:16 pm »
Hi Bart and Eny!

I don't think it. Files and folders have permission to read and execute, even for users. And I can delete it files, from the same account where I'm doing the testing

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Problems with FileExists
« Reply #11 on: April 06, 2013, 06:02:38 pm »
Strange results...

Dir reports:
Code: [Select]
C:\Windows\System32\Macromed\Flash>dir
 De volumenaam van station C is Packard Bell
 Het volumenummer is 94AA-860B

 Map van C:\Windows\System32\Macromed\Flash

25-03-2013  15:53    <DIR>          .
25-03-2013  15:53    <DIR>          ..
25-03-2013  15:49           646.611 activex.vch
25-03-2013  15:49        20.474.072 Flash64_11_6_602_180.ocx
25-03-2013  15:53            18.340 FlashInstall.log
25-03-2013  15:49           530.648 FlashUtil64_11_6_602_180_ActiveX.dll
25-03-2013  15:49           429.784 FlashUtil64_11_6_602_180_ActiveX.exe
25-03-2013  15:53           429.784 FlashUtil64_11_6_602_180_Plugin.exe
25-03-2013  15:53        20.275.416 NPSWF64_11_6_602_180.dll
25-03-2013  15:53           641.683 plugin.vch
               8 bestand(en)       43.446.338 bytes


Test code:
Code: [Select]
program test;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  SysUtils, Classes, Windows;

Function FileExists (Const FileName : String) : String;  //modified from SysUtils
var
  Attr:Dword;
  Res: Boolean;
  Err: DWORD;
begin
  Attr:=GetFileAttributes(PChar(FileName));
  if Attr <> $ffffffff then
    Res:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
  else
    Res:=False;
  if Res then Result := 'True' else Result := 'False';
  Result := Result + ', Attr = ' + IntToHex(Attr, 8);
  if not Res then
  begin
    Err := GetLastError;
    Result := Result + ' (GetLastError=' + IntToHex(Err,8) + ')';
  end;
  //Result := ExtractFileName(FileName) + ': ' + Result;
end;

var
  DosError: LongInt;
  Attr: Longint;
  SR: TSearchRec;
  SL: TStringList;
  i: Integer;
const
  FlashDir = 'C:\Windows\System32\Macromed\Flash\';
begin
  SL := TStringList.Create;
  if ParamStr(1) = '1' then
    begin
    writeln('Iterating ',FlashDir);

    DosError := SysUtils.FindFirst(FlashDir + '*.*',faArchive or faReadOnly or faHidden or faSysFile ,SR);
    while DosError = 0 do
    begin
      writeln('Found: "',SR.Name, '", Attr = ',IntToHex(SR.Attr,8));
      //Sl.Add(SR.Name);
      writeln('FileExists(',SR.Name,') = ',FileExists(FlashDir + SR.Name));
      DosError := SysUtils.FindNext(SR);
    end;
    SysUtils.FindClose(SR);
  end;
  SL.Add('activex.vch');
  SL.Add('Flash64_11_6_602_180.ocx');
  SL.Add('FlashInstall.log');
  SL.Add('FlashUtil64_11_6_602_180_ActiveX.dll');
  SL.Add('FlashUtil64_11_6_602_180_ActiveX.exe');
  SL.Add('FlashUtil64_11_6_602_180_Plugin.exe');
  SL.Add('NPSWF64_11_6_602_180.dll');
  SL.Add('plugin.vch');
  writeln('----------------------');
  for i := 0 to SL.Count - 1 do
  begin
    writeln('FileExists(',SL.Strings[i],') = ',FileExists(FlashDir + SL.Strings[i]));
  end;
  SL.Free;
end.

Output:
Code: [Select]
C:\Windows\System32\Macromed\Flash>\Users\Bart\LazarusProjecten\ConsoleProjecten
\test 1
Iterating C:\Windows\System32\Macromed\Flash\
Found: "activex.vch", Attr = 00000020
FileExists(activex.vch) = True, Attr = 00000020
Found: "Flash32_11_6_602_180.ocx", Attr = 00000021
FileExists(Flash32_11_6_602_180.ocx) = True, Attr = 00000021
Found: "FlashInstall.log", Attr = 00000020
FileExists(FlashInstall.log) = True, Attr = 00000020
Found: "flashplayer.xpt", Attr = 00000020
FileExists(flashplayer.xpt) = True, Attr = 00000020
Found: "FlashPlayerPlugin_11_6_602_180.exe", Attr = 00000020
FileExists(FlashPlayerPlugin_11_6_602_180.exe) = True, Attr = 00000020
Found: "FlashPlayerUpdateService.exe", Attr = 00000020
FileExists(FlashPlayerUpdateService.exe) = True, Attr = 00000020
Found: "FlashUtil32_11_6_602_180_ActiveX.dll", Attr = 00000020
FileExists(FlashUtil32_11_6_602_180_ActiveX.dll) = True, Attr = 00000020
Found: "FlashUtil32_11_6_602_180_ActiveX.exe", Attr = 00000020
FileExists(FlashUtil32_11_6_602_180_ActiveX.exe) = True, Attr = 00000020
Found: "FlashUtil32_11_6_602_180_Plugin.exe", Attr = 00000020
FileExists(FlashUtil32_11_6_602_180_Plugin.exe) = True, Attr = 00000020
Found: "install.log", Attr = 00000020
FileExists(install.log) = True, Attr = 00000020
Found: "mms.cfg", Attr = 00000020
FileExists(mms.cfg) = True, Attr = 00000020
Found: "NPSWF32_11_6_602_180.dll", Attr = 00000020
FileExists(NPSWF32_11_6_602_180.dll) = True, Attr = 00000020
Found: "plugin.vch", Attr = 00000020
FileExists(plugin.vch) = True, Attr = 00000020
----------------------
FileExists(activex.vch) = True, Attr = 00000020
FileExists(Flash64_11_6_602_180.ocx) = False, Attr = FFFFFFFF (GetLastError=00000002)
FileExists(FlashInstall.log) = True, Attr = 00000020
FileExists(FlashUtil64_11_6_602_180_ActiveX.dll) = False, Attr = FFFFFFFF (GetLastError=00000002)
FileExists(FlashUtil64_11_6_602_180_ActiveX.exe) = False, Attr = FFFFFFFF (GetLastError=00000002)
FileExists(FlashUtil64_11_6_602_180_Plugin.exe) = False, Attr = FFFFFFFF (GetLastError=00000002)
FileExists(NPSWF64_11_6_602_180.dll) = False, Attr = FFFFFFFF (GetLastError=00000002)
FileExists(plugin.vch) = True, Attr = 00000020

So, FindFirst finds the files, but GetFileAttributes reports the file is not there.
Even stranger, sometime when running the test program, FileExists reports the files are there ....

Bart
« Last Edit: April 06, 2013, 06:13:14 pm by Bart »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Problems with FileExists
« Reply #12 on: April 06, 2013, 07:01:51 pm »

I'm sorry to insist and I could be wrong, but are you really knowing EXACTLY what you are testing ?

Extract:
"[...] The file system redirector does the magic of hiding the real System32 directory for 32-bit processes and showing SysWOW64 under the name of System32.[...]"

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Problems with FileExists
« Reply #13 on: April 06, 2013, 07:24:43 pm »
In the meantime, if the purpose is to find out if there is 32 or 64 bit flash plugin, you can check that from Windows Registry. I seemed to find it at
HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPlayerActiveX\
PlayerPath = C:\Windows\system32\Macromed\Flash\Flash32_11_6_602_180.ocx

From that information you should be able to extract 32/64. Also it will work even if the windows user actually doesn't have 'C:\Windows\' at all, but like 'C:\MyCustomWinDirName\', as it is changeable on windows installation. Some have 'C:\WinNT\' etc.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Problems with FileExists
« Reply #14 on: April 06, 2013, 08:13:08 pm »

I'm sorry to insist and I could be wrong, but are you really knowing EXACTLY what you are testing ?

Extract:
"[...] The file system redirector does the magic of hiding the real System32 directory for 32-bit processes and showing SysWOW64 under the name of System32.[...]"

I think you are right.
I compared System32 with SYSWOW64 and at first saw different files in SYSWOW64 like  FlashUtil32_11_6_602_180_ActiveX.dll.

Then I launched FreeCommander (32-bit app) and System32 and SYSWOW64 looked exactly the same.
And, it turns out, I didn't even look carefully at the output of my program: it returned the files with 32 in it.

This is why I don't like Windows: it behaves like a virus. It says files are there, when they aren't and vice-versa.
Hey. isn't that just the behaviour virusses have?

Bart

 

TinyPortal © 2005-2018