System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") 返回 false [英] System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") returns false

查看:29
本文介绍了System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") 返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个简单的 .NET 程序以供工作,但遇到了一些我无法弄清楚的奇怪障碍.该应用程序利用配置文件将应用程序添加到下拉菜单.但是,在将其添加到菜单之前,它会执行 system.io.file.exists 以验证该文件是否存在,至少在创建菜单时是这样.

So I am working on a simple .NET program for work and hit a bit of a weird roadblock I can't figure out. The application makes use of a configuration file which adds applications to a dropdown menu. However, before it's added to the menu, it does a system.io.file.exists to verify that the file exists, at least at the time the menu is created.

然而,System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") 返回 false,但可执行文件在那里.同样,stikynot.exe 也返回 false.system32 目录中的其他文件返回 true(如记事本).我可以对这些应用程序进行文件统计,但我的 .net 程序无法读取它们并且 system.io.file.exists 返回 false.我已经检查了各种权限,但没有运气.它似乎与一些应用程序隔离,但我不确定为什么.

However, System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") returns false, but the executable is there. Likewise, stikynot.exe also returns false. Other files in the system32 directory return true(like notepad). I can filestat these applications, but my .net program just can't read them them and system.io.file.exists returns false. I have checked various permissions with no luck. It seems to be isolated to a few applications, but I am not sure why.

推荐答案

这是 64 位 Windows 的一个特性.

That's a feature of 64 bit Windows.

在 x64 中,您有两个包含系统文件的文件夹:system32SysWOW64.

In x64 you have two folders with system files: system32 and SysWOW64.

如果您在system32 中放入任何内容,所有64 位 应用程序都会看到它.SysWOW64 是出于兼容性原因而存在的 - 32 位(原文如此!)应用程序可以看到放在那里的任何内容.

If you put anything in system32, it will be seen by all 64 bit applications. SysWOW64 is there for compatibility reasons - anything put there will be visible by 32 bit (sic!) apps.

因此就 .NET 而言,该文件不存在.它适用于记事本,因为这两个目录中都存在 notepad.exe.

So as far as .NET is concerned, the file does not exist. It works for notepad, because notepad.exe is present in both of those directories.

您可以测试此行为.在其中一个目录中创建一个文本文件,但不在另一个目录中,并检查它是否存在.然后在 x86 和 x64 之间更改您的项目配置(右键单击解决方案 -> 配置管理器)并享受结果.

You can test this behaviour. Create a text file in one of the directories, but not the other and check for its existence. Then change your project configuration (right click on solution -> Configuration Manager) between x86 and x64 and enjoy the result.

这篇关于System.IO.File.Exists(@"C:WindowsSystem32SnippingTool.exe") 返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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