【发布时间】:2012-12-10 23:26:08
【问题描述】:
当我尝试从我的 C# 应用程序运行 BCDEDIT 时,我收到以下错误:
'bcdedit' 未被识别为内部或外部 命令, 可运行的程序或批处理文件。
当我通过提升的命令行运行它时,我得到了预期的结果。
我使用了以下代码:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = @"CMD.EXE";
p.StartInfo.Arguments = @"/C bcdedit";
p.Start();
string output = p.StandardOutput.ReadToEnd();
String error = p.StandardError.ReadToEnd();
p.WaitForExit();
return output;
我也尝试过使用
p.StartInfo.FileName = @"BCDEDIT.EXE";
p.StartInfo.Arguments = @"";
我尝试了以下方法:
- 检查路径变量 - 它们没问题。
- 从提升的命令提示符运行 Visual Studio。
- 放置完整路径。
我的想法不多了, 关于我为什么会收到此错误的任何想法?
如果还有其他方法也可以,我需要的只是命令的输出。 谢谢
【问题讨论】:
-
尝试将 bcdedit 放入您的 debug/bin 文件夹,看看是否可行。你也可以直接调用 BCDEDIT,你不必运行 cmd.exe
-
@Mataniko,谢谢 - 将它放在调试目录中似乎可行,但为什么在 system32 路径中找不到呢?
-
这是路径设置,David Heffernan 的回答似乎是罪魁祸首。