即使文件存在,FileExists() 返回 false
我想检查System32目录(Windows 7)中的dll是否存在。但即使存在,FileExists() 也会返回 false。 LoadLibrary 返回一个有效的句柄。 在这种情况下,我只想检查文件是否存在并可视化此信息。 您有什么建议可以解决这个问题吗?
I want to check if a dll in System32 directory (Windows 7) exists. But even if it exists, FileExists() returns false. LoadLibrary returns a valid handle.
In this case, I only want to check, if the files exists and visualize this information.
Do you have a any tips to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这很可能是由于文件重定向造成的。您有一台 64 位计算机,但从 32 位 Delphi 进程中,
Windows\system32
实际上重定向到Windows\Syswow64
。因此,当您认为自己在询问Windows\system32
中是否存在文件时,系统实际上是在报告Windows\Syswow64
中存在(或以其他方式)文件。 。如果您确实需要了解真正的 64 位 system32,那么您需要禁用文件重定向。您可以使用 <代码>Wow64DisableWow64FsRedirection()函数。不要忘记使用
Wow64RevertWow64FsRedirection()
将其重新打开。请注意,禁用重定向器会产生广泛的影响,并可能导致非常奇怪的行为,因此请务必小心。Most likely this is down to file redirection. You have a 64 bit machine but from the 32 Delphi process,
Windows\system32
actually redirects toWindows\Syswow64
. So when you think you are asking for the existence of a file inWindows\system32
, the system is actually reporting the existance (or otherwise) of a file inWindows\Syswow64
.If you really do need to see into the true 64 bit system32 then you need to disable file redirection. You can do this with the
Wow64DisableWow64FsRedirection()
function. Don't forget to switch it back on withWow64RevertWow64FsRedirection()
. Beware that disabling the redirector has wide reaching effects and can result in very strange behaviour so do so with care.没有太多信息可以继续,您正在使用的代码可能会有所帮助,但这可能是 64 位问题并且 dll 实际上位于 SysWOW64 文件夹中吗?请参阅此处 详细描述了其工作原理。
Not much information to go on, the code you are using might help, but could this be a 64 bit issue and that the dll is actually in the SysWOW64 folder? See here for a good description of the how this works.
几乎可以肯定,您没有在
FileExists
调用中指定文件的完整或有效相对路径。LoadLibrary
将为您搜索某些位置(DLL 预计驻留的位置),但FileExists
不会。提供完整且正确的路径,FileExists
将正常工作。You are almost certainly not specifying the full or valid relative path of the file in your
FileExists
call.LoadLibrary
will search certain locations (those where dlls are expected to reside) for you, butFileExists
will not. Supply the complete and correct path andFileExists
will work correctly.这是最荒谬的原因,但如果它只能帮助一个人……
请确保您没有意外地将文件命名为
something.dll.dll
。我刚刚遇到过这样的情况:我在客户端计算机上安装了一个应用程序,然后该应用程序找不到位于同一目录中的
config.txt
。这在其他计算机上运行得很好,所以我当然被难住了。事实证明,该客户端计算机上的“显示文件扩展名”设置已关闭,并且该文件实际上已命名为
config.txt.txt
...我要辩解说,我花了 90% 的时间在 OSx 上,9.99% 在我自己的 Windows 系统上,很久以前就启用了“显示文件扩展名”。This is the most ridiculous reason, but if it can help just one person...
Make sure you didn't accidentally name the file
something.dll.dll
.I just had a situation where I installed an application on a clients computer, and then the application couldn't find
config.txt
located in the same directory. This had been working fine on other computers, so of course I was stumped.Turns out the "show file extensions" setting was turned off on this clients computer, and the file had actually been named
config.txt.txt
... in my defence, I spend 90% of the time on OSx, and 9.99% on my own Windows system, with "show file extensions" enabled since ages ago.