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

sd_*_*ula 3 c# batch-file winforms

我从我的c#winforms应用程序运行:

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

if (File.Exists(ExecutableFilePath )) {
    System.Diagnostics.Process.Start(ExecutableFilePath , Arguments);
}
Run Code Online (Sandbox Code Playgroud)

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

有没有办法让它运行而不向用户显示?

Ste*_*eve 9

您应该使用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);
  }
Run Code Online (Sandbox Code Playgroud)