使用 VS 15、C# 和 .Net 4.5.2
该计算机位于 AD 网络上,广告名称为“AD”。
AD 普通用户权限、AD 管理员权限和本地管理员权限都会出现此问题。无论程序获得什么权限,都会出现同样的问题。
我们的测试文件是“C:/windows/system32/conhost.exe".
上面的文件存在,它非常存在。我可以用资源管理器看到它。
This is the file in explorer:
This is the file properties:
你可以看到它就在那里,对吗?
以下 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 和其他一些文件。例如,它发现“connect.dll”位于system32中,因此它不是该目录的读取权限。
更多额外说明:conhost.exe 和 connect.dll 具有相同的安全属性(文件属性中的“安全”选项卡)。