FileExists () returns false even if the file exists

I want to check if a dll exists in the System32 directory (Windows 7). But even if it exists, FileExists () returns false. LoadLibrary returns a valid handle. In this case, I only want to check if the files exist and visualize this information. Do you have any tips to fix it?

+6
source share
3 answers

This is most likely due to file redirection. You have a 64-bit machine, but from the 32 Delphi process, Windows\system32 actually redirected to Windows\Syswow64 . Therefore, when you think that you are requesting the existence of a file in Windows\system32 , the system actually reports the existence (or otherwise) of the file in Windows\Syswow64 .

If you really need to see a true 64-bit system32, you need to disable file redirection. You can do this with the Wow64DisableWow64FsRedirection() function. Remember to enable it again with Wow64RevertWow64FsRedirection() . Beware that disabling the redirector has a wide coverage effect and can lead to very strange behavior, so do this with caution.

+21
source

There is not much information to use the code you are using, but can it be a 64-bit problem and that the dll really is in the SysWOW64 folder? See here for a good description of how this works.

+10
source

You almost never specify the full or valid relative file path in your call to FileExists . LoadLibrary will look for specific locations (those where dlls will reside) for you, but FileExists will not. Set the full and correct path and FileExists will work correctly.

+2
source

Source: https://habr.com/ru/post/898484/


All Articles