Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Winforms and command line batch files

I have this running from my c# winforms app:

string ExecutableFilePath = @"Scripts.bat";
string Arguments = @"";

if (File.Exists(ExecutableFilePath )) {
    System.Diagnostics.Process.Start(ExecutableFilePath , Arguments);
}

When that runs I get to see the cmd window until it finishes.

Is there a way to get that to run without showing it to the user?

like image 544
sd_dracula Avatar asked Jan 14 '23 13:01

sd_dracula


1 Answers

You should use ProcessStartInfo class and set the following properties

  string ExecutableFilePath = @"Scripts.bat";
  string Arguments = @"";

  if (File.Exists(ExecutableFilePath ))
  {
       ProcessStartInfo psi = new ProcessStartInfo(ExecutableFilePath , Arguments);
       psi.UseShellExecute = false;
       psi.CreateNoWindow = true;
       Process.Start(psi);
  }
like image 92
Steve Avatar answered Jan 24 '23 22:01

Steve