检查文件是否在64位系统的使用存在File.Exists [英] check if file exist on 64 bits system using File.Exists

查看:409
本文介绍了检查文件是否在64位系统的使用存在File.Exists的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是64位,在foler C:\Windows\SysWOW64有一个文件111.txt,但没有在c文件:\windows\system32

My OS is 64 bits and in the foler C:\Windows\SysWOW64 there is a file 111.txt, but there is not the file in c:\windows\system32

但follwoing代码还真

but the follwoing code return true

file = @"C:\Windows\System32\111.txt";    
bool bExist = System.IO.File.Exists(file);



我不知道为什么?我怎么能检查是否有system32下的文件111.txt没有SYSWOW64?

I don't know why? and how can i check if there is the file 111.txt under system32 not SysWoW64?

推荐答案

由于如此多的应用都硬编码System32目录名称为路径,MS把64位系统上的文件,而不是出现在一个System64目录下。 32位版本进入一个'Syswow64资料目录(这是相当混乱)。但为了防止破32位程序时,系统默认情况下执行的尝试访问System32下'目录的32位进程重定向。在大多数情况下,当一个32位应用程序试图访问%WINDIR%\System32,访问被重定向到%WINDIR%\SysWOW64。

Because so many applications have hard-coded the System32 directory name into paths, MS put the 64-bit systems files there instead of in a 'System64' directory. The 32-bit versions now go into a 'SysWOW64' directory (it's quite confusing). but in order to prevent breaking 32-bit programs, the system performs a redirection by default for 32-bit processes trying to access the 'System32' directory. In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.

一个简单的方法要解决这个重定向是使用%WINDIR%\Sysnative 而非%WINDIR%\System32。 Win64平台将重定向该目录的实际System32目录中。

A simple way to get around this redirection is to use %windir%\Sysnative instead of %windir%\System32. Win64 will 'redirect' that directory to the actual System32 directory.

您可以使用 Wow64DisableWow64FsRedirection()的API彻底禁用重定向。请参见 http://msdn.microsoft.com/en-us/library/aa384187.aspx 了解详情。

You can use the Wow64DisableWow64FsRedirection() API to completely disable this redirection . See http://msdn.microsoft.com/en-us/library/aa384187.aspx for details.

这篇关于检查文件是否在64位系统的使用存在File.Exists的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆