Want to hide cmd prompt screen

I developed a utility that will get the time of all the servers in the list.

System.Diagnostics.Process p; string server_name = ""; string[] output; p = new System.Diagnostics.Process(); p.StartInfo.FileName = "net"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StandardOutput.ReadLine().ToString() 

When executing this code. Cmd prompt screens will appear. I want to hide this from the user. What can I do for this?

+6
source share
4 answers

You can say that the process does not use a window or minimizes it:

 // don't execute on shell p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; // don't show window p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; 

with UseShellExecute = false you can redirect the output:

 // redirect standard output as well as errors p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; 

When you do this, you should use asynchronous reading of the output buffers to avoid a deadlock due to overflowing buffers:

 StringBuilder outputString = new StringBuilder(); StringBuilder errorString = new StringBuilder(); p.OutputDataReceived += (sender, e) => { if (e.Data != null) { outputString.AppendLine("Info " + e.Data); } }; p.ErrorDataReceived += (sender, e) => { if (e.Data != null) { errorString.AppendLine("EEEE " + e.Data); } }; 
+11
source

Try the ProcessWindowStyle listing as follows:

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

Hidden window style. A window can be either visible or hidden. the system displays a hidden window without drawing it. If the window is hidden, it is effectively disabled. A hidden window can process messages from the system or from other windows, but it cannot process input from a user’s output or display. Often an application can keep a new window hidden when it adjusts the appearance of the window, and then create the Normal window style. Use the ProcessWindowStyle.Hidden , ProcessStartInfo.UseShellExecute property must be false .

+4
source

Try these

 p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

or check it also

To start a child process without any window,

use the CreateNoWindow property and set UseShellExecute.

 ProcessStartInfo info = new ProcessStartInfo(fileName, arg); info.CreateNoWindow = true; info.UseShellExecute = false; Process processChild = Process.Start(info); 

I suggest you go to this MSDN post: How to start a console application in a new window, a parent window or without a window

0
source

Add system link.

 using System.Diagnostics; 

Then use this code to run your command in a hidden CMD window.

 Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; cmd.StartInfo.Arguments = "Enter your command here"; cmd.Start(); 
0
source

All Articles