Sign in to follow this  
Followers 0
ScriptingSteve

FileExists() returns false in error when x86-compiled script runs on x64 Win 7

5 posts in this topic

I have a 32-bit-compiled autoit script that is returning false in error when run on 64-bit Windows 7 for this code:

{{

$Dir=@WindowsDir & "\System32\Drivers\mrxsmb10.sys"

If FileExists($Dir) Then

Msgbox(64,"File found","File '" & $Dir & "' Version " & FileGetVersion($Dir))

Else

Msgbox(16,"Error","File '" & $Dir & "' not found.")

EndIf

}}

The file is physically in the above location (C:\Windows\System32\Drivers\Mrxsmb10.sys). When the script is compiled x86 (AutoIt 3360), it returns false (incorrect). If the same script is recompiled as x64(AutoIt 3360), it returns true (correct).

The interesting thing here is that on a 64-bit Win7 machine, this file is NOT within C:\Windows\SysWOW64\..., it is sitting at the absolute path "C:\Windows\System32\Drivers\Mrxsmb10.sys".

Thus the "If Fileexists($Dir)" from above is looking for this file at path "C:\Windows\System32\Drivers\Mrxsmb10.sys", (I validated this through debugging that variable substitution was correct). Visually verified as being present at the above path on 64-bit Windows 7.. yet 32-bit compiled script returns false (file does not exist, even when it does), but the same script, recompiled 64-bit, returns true (file exists), correct.

Unless I'm missing something obvious, I suspected this as an AutoIt bug, but am told to discuss here first. Looking for any suggestions..

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

When running in X64 mode the c:\windows\System32 directory is used and when in x86 mode any reference to c:\windows\system32 will use C:\Windows\SysWOW64. This is standard Vista/Win7 behaviour.

Try running this script in SciTE with both a Y and a N on the first line and look at the files returned. (need the full SciTE4AutoIt3 version for that)

#AutoIt3Wrapper_usex64=y
$Dir = @WindowsDir & "\System32\Drivers\*.sys"
FileFindFirstFile($Dir)
$search = FileFindFirstFile($Dir)
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    ConsoleWrite($file)
    ConsoleWrite(@CRLF)
WEnd
FileClose($search)
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

try sysnative if running under wow emulation

If @OSArch = "X64" AND @AutoItX64 = 0 Then
    $Dir=@WindowsDir & "\Sysnative\Drivers\mrxsmb10.sys"
Else
    $Dir=@WindowsDir & "\System32\Drivers\mrxsmb10.sys"
EndIf

Yes, the "sysnative" technique did work correctly. Thanks to all for assistance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0