简体   繁体   English

C#File.Exist(File_Path)返回false,即使File_Path为true,文件存在并且我有权访问该文件

[英]C# File.Exist(File_Path) Returns false even if File_Path is true, file exists and i have rights to access that file

I'm writing a software which will run on Windows 7. I'm listing installed services, getting service's image path locations and checking if service file exists.(Dll or Exe). 我正在写一个将在Windows 7上运行的软件。我正在列出已安装的服务,获取服务的图像路径位置,并检查服务文件是否存在。(Dll或Exe)。

I'm checking file locations with File.Exist(File_Path) . 我正在使用File.Exist(File_Path)检查文件位置。 For some files, it returns false even if file path is true , file exists and I have rights to Access that file. 对于某些文件,即使文件路径为true ,文件也存在,并且我有权访问该文件,它仍返回false

I know that even if that file exists, if the user don't have the rights to Access it File.Exist(File_Path) returns false. 我知道即使该文件存在,如果用户没有访问该File.Exist(File_Path)权限, File.Exist(File_Path)返回false。

For example, it returns true for the file C:\\Windows\\System32\\appmgmts.dll but it returns false for the file C:\\Windows\\System32\\audiosrv.dll 例如,它的文件返回true C:\\Windows\\System32\\appmgmts.dll但它返回假文件C:\\Windows\\System32\\audiosrv.dll

And when I look user permissions for these 2 files under the Windows explorer, they are exactly same. 当我在Windows资源管理器中查看这两个文件的用户权限时,它们是完全相同的。 But File.Exist(File_Path) returns different answers for these files. 但是File.Exist(File_Path)对于这些文件返回不同的答案。

I'm running Visual Studio, and Exe file as an Administrator. 我正在运行Visual Studio,并且以管理员身份运行Exe文件。

Please give me some advices for this strange behavior. 请给我一些有关这种奇怪行为的建议。

当我在x86配置中执行File.Exists时,我得到的结果是相同的,但是当我64岁时,这两个文件返回true,并且在网上发现SysWOW64中您搜索的File.Exists时,请查看此问题以获取更多信息: 使用File.Exists检查文件是否在64位系统上存在

I fixed a similar issue that occurred while checking files over a mapping that I created with my domain credentials. 我修复了在通过使用域凭据创建的映射检查文件时发生的类似问题。 I was debugging VS as an Administrator. 我以管理员身份调试VS。 I was able to navigate through Windows Explorer to the file but not with VS. 我可以通过Windows资源管理器导航到该文件,但不能使用VS。

I solved the problem when I closed VS Admin mode and started it normally back again. 当我关闭VS Admin模式并重新正常启动时,我解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM