【发布时间】:2014-03-18 19:59:05
【问题描述】:
我有一个需要隐藏的进程,我尝试了以下代码行将其隐藏:
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
第一行只是简单地使它不可见,第二行抛出以下错误:
"{"StandardOut 尚未重定向或进程尚未开始。"}
我还需要将输出重定向到富文本框和剪贴板,所以我不能将 redirectstandardoutput 设置为 false。 这是我创建流程的函数。
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = pingData;
p.Start();
p.WaitForExit();
string result = p.StandardOutput.ReadToEnd();
System.Windows.Forms.Clipboard.SetText(result);
if(p.HasExited)
{
richTextBox1.Text = result;
outPut = result;
MessageBox.Show( "Ping request has completed. \n Results have been copied to the clipboard.");
}
谢谢
【问题讨论】:
标签: c# process hidden processstartinfo