Question

I have a process that I need hidden, I have tried the following lines of code to make it hidden:

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;

The first line just simply does not make it non-visible and the second throws the following error:

"{"StandardOut has not been redirected or the process hasn't started yet."}

Also I need to have the output redirected to a richtextbox and the clipboard, so I cannot set redirectstandardoutput to false. Here is my function for creating the process.

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.");                
        }

Thanks

Était-ce utile?

La solution

Remove the following line:

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

Keep these two lines:

p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;

WindowStyle only applies to native Windows GUI applications.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top