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

标签 c# winforms batch-file

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

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

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

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

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

最佳答案

你应该使用 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);
  }

关于C# Winforms 和命令行批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14225020/

相关文章:

c# - IsBalloon 属性使 Windows 窗体工具提示位置不一致

winforms - 使用 WinForms 的 MVVM/表示模型

windows - 检查是否安装了 WMIC,将数据从批处理文件写入文件

c# - 读取xml文件的多个子节点

C# 在 Windows 7 中隐藏任务栏

c# - 在 Linux 上运行 Windows 窗体应用程序

c# - 在 MVC 上执行编辑时如何保留某些字段的原始值?

c# - 在 winforms 应用程序上绘制相反(反向)颜色

Windows 7 循环批处理文件

windows - 在运行批处理文件时隐藏 CMD