Avoid Console Flash On Screen

Ok, one more question!  If I use this code (courtesey of eternal 21):

                  System.Diagnostics.Process process = new System.Diagnostics.Process();
                  process.StartInfo.FileName = "cmd";
                  process.StartInfo.UseShellExecute = false;
                  process.StartInfo.Arguments = "/c net send * hello world!";
                  process.Start();

Is there a way to hide the console flashing on the screen when executing command line commands?
LVL 1
fattumsdadAsked:
Who is Participating?
 
eternal_21Commented:
Oh man, am I getting rusty or what? :)

For a Windows Application OR a Console Application:

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

You can forget about the redirect error statements, they will not be necessary if you are using "CreateNoWindow = true".  Sorry about the confusion, fattumsdad.
0
 
eternal_21Commented:
Sorry, fattumsdad:

  process.StartInfo.RedirectStandardOutput = true;
  process.StartInfo.RedirectStandardError = true;
0
 
eternal_21Commented:
I had used 'UseShellExecute = false' so that you did not see another window, but assumed that you were in a Windows Application, not a Console Application!

- eternal
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
fattumsdadAuthor Commented:
eternal,

I am in a Windows Application :) When I click on button1 to execute the command, a console window pops up for a split second and executes it, then disappears. :)
0
 
fattumsdadAuthor Commented:
When I add:

process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;

It still flashes a "command prompt" for a second :(
0
 
fattumsdadAuthor Commented:
eternal,

Rusty or not, you're still helping me out quite a bit!!  Works great, thanks again!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.