Jump to content

Fileexist not working properly


legend
 Share

Recommended Posts

if FileExists("C:\Windows\System32\dsac.exe") Then
        MsgBox("","","the file exists! and we are happy :)")
Else
        MsgBox("","","please download microsoft remote administration tools",3)
        ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=45520")
EndIf

I have this weird issue that I can't check if this file exist: dsac.exe.

I will tell the file does not exist, even if it does:

DLRIAYF.png

 

If i check if notepad.exe exist, or if mspaint.exe exist, witch is also in system32,  then it works fine, it will say that it exist,

I tried to check the rights on dsac.exe, it's exactly the same as on notepad.exe

 

Link to comment
Share on other sites

If you're running under 64-bit Windows, look up SysWow64; and then I would suggest you use macro @SystemDir instead of hard-coding the path.

Edited by RTFC
Link to comment
Share on other sites

@SystemDir stores the 32 bits path with a script running in 32 bits.

In a x64 Windows, a 32 bits application maps the system32 directory to c:\windows\syswow64 (it's the WOW6432 redirection).
So when the application accesses to c:\windows\system32, it accesses to the c:\windows\syswow64 folder.

You can enable or disable the WOW6432 redirection using _WinAPI_Wow64EnableWow64FsRedirection(True/False).
But don't use @SystemDir, because it always returns the Syswow64 path (with a 32 bits running script). You can use _WinAPI_ShellGetKnownFolderPath($FOLDERID_System) instead

#include <WinAPIFiles.au3>
#include <WinAPIShellEx.au3>

_WinAPI_Wow64EnableWow64FsRedirection(False)
Local $sSystem32 = _WinAPI_ShellGetKnownFolderPath($FOLDERID_System)

If FileExists($sSystem32 & "\dsac.exe") Then
        MsgBox("","","the file exists! and we are happy :)")
Else
        MsgBox("","","please download microsoft remote administration tools",3)
        ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=45520")
EndIf

Another way, is the use the Sysnative folder. In this case, you don't need to disable the WOW6432 redirection :

Local $sSystem32 = FileExists(@WindowsDir & "\sysnative") ? @WindowsDir & "\sysnative" : @SystemDir

If FileExists($sSystem32 & "\dsac.exe") Then
        MsgBox("","","the file exists! and we are happy :)")
Else
        MsgBox("","","please download microsoft remote administration tools",3)
        ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=45520")
EndIf

 

Link to comment
Share on other sites

2 hours ago, jguinch said:

@SystemDir, because it always returns the Syswow64 path (with a 32 bits running script)

@jguinch: This is true, but when I run this little test based upon your first example:

#include <WinAPIFiles.au3>
#include <WinAPIShellEx.au3>

_WinAPI_Wow64EnableWow64FsRedirection(True)
$sSystem32 = _WinAPI_ShellGetKnownFolderPath($FOLDERID_System)
MsgBox(0,$sSystem32,@systemdir)

_WinAPI_Wow64EnableWow64FsRedirection(False)
$sSystem32 = _WinAPI_ShellGetKnownFolderPath($FOLDERID_System)
MsgBox(0,$sSystem32,@systemdir)

_WinAPI_ShellGetKnownFolderPath appears equally insensitive to redirection, always returning C:\WINDOWS\system32 (at least on my x64 machine+OS running a 32-bit script). I interpreted your response as suggesting that ShellGetKnownFolderPath  would reflect the redirection status, or did I miss/misinterpret something?

 

2 hours ago, jguinch said:

{unable to delete this silly box}

Edited by RTFC
Link to comment
Share on other sites

@RTFC : with or without the redirection, the System directory is always c:\windows\system32. With a 32 bits script, you can use $FOLDERID_SystemX86 the get x86 system path. But in this case, $FOLDERID_System returns the desired value

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...