-1

我正在创建一个必须与 Windows 系统程序(如C:\windows\System32\bcdedit.exe. 例如,如果我尝试达到mspaint它的效果很好。

IO.File.Exists(@"C:\windows\System32\mspaint.exe") // return true

IO.File.Exists(@"C:\windows\System32\bcdedit.exe") // return false

这将返回 false,但该文件确实存在。我可以在 Windows 资源管理器中看到它,我可以从命令行启动它。仅对于我的 c# 应用程序,此文件无法访问。当我想启动它时,我收到错误 Win32Exception 并显示以下消息:

该系统找不到指定的文件

当我“询问”文件是否存在(通过上面的代码)时,它返回 false。

为什么?

4

1 回答 1

0

尝试以下操作,这应该返回 true。

IO.File.Exists(@"C:\windows\System32\bcdedit.exe");

这是一个测试示例:

string curFile = @"C:\windows\System32\bcdedit.exe";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");

参考:https ://msdn.microsoft.com/en-us/library/system.io.file.exists(v=vs.110).aspx

如果这不起作用,那么最有可能的问题是x64or x86。因此,您应该将构建配置为AnyCPU并再次对其进行测试。

在此处输入图像描述

更多信息可以在这里找到。

于 2015-12-23T19:55:31.580 回答