【问题标题】:C# New process window does not hide [duplicate]C#新进程窗口不隐藏[重复]
【发布时间】:2012-06-24 16:38:02
【问题描述】:

可能重复:
Hide Command Window in C# Application

在控制台应用程序中,我想运行 cmd 命令,但是正在创建一个新窗口,为什么?

 Process process = new Process();
 ProcessStartInfo startInfo = new ProcessStartInfo();
 startInfo.WindowStyle = ProcessWindowStyle.Hidden;
 startInfo.CreateNoWindow = true;
 startInfo.UseShellExecute = false;
 startInfo.FileName = "cmd.exe";
 startInfo.WorkingDirectory = @"C:\m_f";
 startInfo.Arguments = "/c START _creator.bat";
 process.StartInfo = startInfo;
 process.Start();

编辑

我不得不将一些代码更改为:

 startInfo.FileName = @"C:\m_f\_creator.bat";
 startInfo.WorkingDirectory = @"C:\m_f\";
 startInfo.Arguments = "some_args";

现在可以了

【问题讨论】:

  • 控制台应用程序与您在此处作为外部进程启动的命令提示符(cmd.exe)不同。
  • 你的问题是START,删除它。
  • 你自己搞定了!窗口不是cmd.exe,是cmd.exe启动的程序。所以你启动程序本身来隐藏它。
  • 另一个选项是将 /B 作为选项传递给 START - 这将运行命令而不创建另一个窗口。

标签: c# process


【解决方案1】:

start 生成一个新窗口,无论父 shell 是否有窗口。

运行批处理文件cmd /c foo.cmd 就足够了,甚至foo.cmd

【讨论】:

  • 虽然foo.cmd 是一个更好的主意,但您可以将/B 选项传递给start 以不创建新窗口,如我在上面的评论中所述。
猜你喜欢
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 2015-11-09
  • 2010-11-11
  • 2010-10-21
相关资源
最近更新 更多