C#Winforms和命令行批处理文件

时间:2013-01-08 22:19:45

标签: c# winforms batch-file

我从c#winforms app开始运行:

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

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

当它运行时,我会看到cmd窗口,直到它完成。

有没有办法让它在没有向用户显示的情况下运行?

1 个答案:

答案 0 :(得分:8)

您应该使用ProcessStartInfo类并设置以下属性

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