C#hide,background,processinfo

时间:2011-06-28 04:08:21

标签: c#

我有这段代码:

ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = true;
Process p = Process.Start(PSI);

问题是,当我构建它时,仍然会出现命令提示符。我怎么能隐藏它?谢谢!

2 个答案:

答案 0 :(得分:1)

在Visual Studio中,将项目属性中Application下的输出类型更改为Windows Application。

项目属性>申请>输出类型:“Windows应用程序”

还可以尝试:

PSI.UseShellExecute = false;

答案 1 :(得分:0)

复制粘贴代码后,您可能没有注意到一个例外。 To redirect the IO streams, the UseShellExecute property must be set to false.

此外,PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;不是必需的。这是您的工作代码:

ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
//PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = Process.Start(PSI);