C#无法看到Windows程序

时间:2015-12-23 19:47:45

标签: c# windows process file-not-found bcdedit

我正在创建一个程序,必须使用像C:\windows\System32\bcdedit.exe这样的Windows系统程序。如果我尝试以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。

为什么?

1 个答案:

答案 0 :(得分:0)

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

2n+2

以下是测试的示例:

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

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

如果这不起作用,那么问题很可能是string curFile = @"C:\windows\System32\bcdedit.exe"; Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist."); x64。因此,您应该将构建配置为x86并再次测试。

enter image description here

可以找到更多信息here

相关问题