通过C#运行时无法识别BCDEDIT [英] BCDEDIT not recognized when running via C#
本文介绍了通过C#运行时无法识别BCDEDIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试从C#应用程序运行BCDEDIT时,出现以下错误:
When i try to run BCDEDIT from my C# application i get the following error:
'bcdedit'不被识别为内部或外部命令,可操作的程序或批处理文件.
'bcdedit' is not recognized as an internal or external command, operable program or batch file.
当我通过提升的命令行运行它时,我得到了预期的结果.
when i run it via elevated command line i get as expected.
我使用了以下代码:
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.
- 放置完整路径.
我的想法不多了,关于为什么我会收到此错误的任何想法吗?
i am running out of ideas, any idea as to why i am getting this error ?
如果还有另一种方法也可以的话,我所需要的就是命令的输出.谢谢
all i need is the output of the command if there is another way that would work as well. thanks
推荐答案
有一种解释很有意义:
- 您正在64位计算机上执行程序.
- 您的C#程序构建为x86.
-
bcdedit.exe
文件存在于C:\ Windows \ System32
中. - 尽管
C:\ Windows \ System32
位于系统路径上,但是在x86进程中,您必须遵守
- You are executing the program on a 64 bit machine.
- Your C# program is built as x86.
- The
bcdedit.exe
file exists inC:\Windows\System32
. - Although
C:\Windows\System32
is on your system path, in an x86 process you are subject to the File System Redirector. Which means thatC:\Windows\System32
actually resolves toC:\Windows\SysWOW64
. - There is no 32 bit version of
bcdedit.exe
inC:\Windows\SysWOW64
.
解决方案是将C#程序更改为目标 AnyCPU
或 x64
.
The solution is to change your C# program to target AnyCPU
or x64
.
这篇关于通过C#运行时无法识别BCDEDIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文