I have developed a utility which will get time of all 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()
While executing this code. Cmd prompt screens are coming. I want to hide it from the user. What can I do for it?
You can tell the process to use no window or to minimize 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 may 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 overfilled 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);
}
};
Try with ProcessWindowStyle
enumeration like this;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
The hidden window style. A window can be either visible or hidden. The system displays a hidden window by not drawing it. If a 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 the user or display output. Frequently, an application may keep a new window hidden while it customizes the window's appearance, and then make the window style Normal. To use ProcessWindowStyle.Hidden, the ProcessStartInfo.UseShellExecute property must be false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With