首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

[]C#执行CMD没有执行结果有关问题

2013-09-09 
[求助]C#执行CMD没有执行结果问题本帖最后由 sleepsophy 于 2013-09-06 18:58:02 编辑因为要执行CMD命令昨

[求助]C#执行CMD没有执行结果问题
本帖最后由 sleepsophy 于 2013-09-06 18:58:02 编辑 因为要执行CMD命令昨天写的一块代码去执行bcdedit,当时执行这段代码是没什么问题的,可以返回一句执行成功的话,但是今天返回值成空了,今天运行的结果如下:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\\Users\\Documents\\Visual Studio 2010\\Projects\\Tmp\\Tmp\\bin\\Debug>time /t
18:33
C:\\Users\\Documents\\Visual Studio 2010\\Projects\\Tmp\\Tmp\\bin\\Debug>bcdedit /set {current} bootstatuspolicy ignoreallfailures

上面一条测试用的可以输出返回值时间,但下面一条,单独在cmd里执行是有结果的,昨天刚写完初步测试也是有返回结果的,输出“The operation completed successfully.”,但是今天再运行这块代码的时候没有输出操作成功的结果,这中间我是什么都没有更改的,代码还是以前的代码,←不想说“昨天”、“今天”这种不科学的论调但是很诡异调了一下午了求帮助求灵感一 一……以下是代码……
            
            Process process = new Process();
            process.StartInfo.FileName = @"cmd.exe";
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.CreateNoWindow = true;
            process.Start();
            process.StandardInput.AutoFlush = true;
            process.StandardInput.WriteLine("bcdedit /set {current} bootstatuspolicy ignoreallfailures");
            process.StandardInput.WriteLine("");
            process.StandardInput.WriteLine("exit");

            string output = process.StandardOutput.ReadToEnd();
            MessageBox.Show(output);
            process.Close(); C# Process CMD


[解决办法]
你debug进去调试下看看的 
[解决办法]
你单独写个测试程序跑下呢,用你上面的代码应该包含全部输出的:
[]C#执行CMD没有执行结果有关问题
你看path中不会有其它乱七八糟的bcdedit吧,不会有同名的bat文件吧?
还可以试下添加:app.manifest,把里面的:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
换成:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

热点排行