C# Winforms and command line batch files

会有一股神秘感。 提交于 2020-01-14 13:59:08

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/14225020/c-sharp-winforms-and-command-line-batch-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!