【发布时间】:2017-08-16 01:54:45
【问题描述】:
在 .Net 4.5.2 中使用 VS 15、C#
计算机位于 AD 网络上,广告名称为“AD”。
AD 普通用户权限、AD 管理员权限和本地管理员权限会出现此问题。不管程序获得什么权利,都会出现同样的问题。
我们的测试文件是“C:/windows/system32/conhost.exe”。
上面的文件存在,它非常存在。我可以用资源管理器看到它。
你可以看到它在那里,对吧?
以下 cmd 命令检查文件是否存在:
IF EXIST "C:\windows\system32\conhost.exe" (echo does exist) ELSE (echo doesnt exist)
它按照承诺返回“确实存在”。
以下 C# 代码检查文件是否存在:
FileInfo file = new FileInfo("C:/windows/system32/conhost.exe");
MessageBox.Show(file.Exists + "");
这将返回“False”。
此代码还返回“False”:
MessageBox.Show(File.Exists("C:/windows/system32/conhost.exe") + "");
这段代码也找不到:
foreach (string file in Directory.GetFiles("C:/windows/system32/"))
{
//conhost is NEVER mentioned, like it doesn't exist
}
这段代码也找不到:
foreach (string file in Directory.EnumerateFiles("C:/windows/system32/"))
{
//conhost is NEVER mentioned, like it doesn't exist
}
假,假,假:
MessageBox.Show(File.Exists("C:/windows/system32/conhost.exe") + "");
MessageBox.Show(File.Exists("C:\\windows\\system32\\conhost.exe") + "");
MessageBox.Show(File.Exists(@"C:\windows\system32\conhost.exe") + "");
我做错了什么?
额外说明:我将 conhost 复制到 C:\conhost.exe,我的程序可以毫无问题地找到它。我的程序还在 system32 中找到了其他文件,只是没有找到 conhost 和其他一些文件。比如找到system32中的“connect.dll”,所以不是目录的读权限。
更多额外说明:conhost.exe 和 connect.dll 具有相同的安全属性(文件属性中的安全选项卡)。
【问题讨论】:
-
你试过把 / 改成 \ 吗?
-
试试
File.Exists(@"C:\windows\system32\conhost.exe") -
64 位应用程序和重定向可能...
-
问题是您提出问题的地方,而不是您发布答案的地方。如果您想发布您自己的答案,以及其他人提供的答案,请将其发布为作为答案。如果现有答案充分回答了问题,那么当然没有必要这样做。
-
不相关,但所有
+ ""的东西都用完了吗?摆脱那些无用的垃圾。如果你打算做.ToString(),那么就去.ToString()。或者使用字符串插值......无论如何。+ ""看起来不太对。
标签: c# file file-exists