3

我正在尝试从我的 C# 控制台应用程序运行 VLC,但我不能。我知道还有其他类似的问题(例如Launching process in C# without Distracting Console WindowC# Run external console application and no ouptut?C#: Run external console program as hidden)并从中我得出以下代码:

        Process process = new Process();
        process.StartInfo.FileName = "C:\\Users\\XXXXX\\Desktop\\VLC\\vlc.exe";
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;
        //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        process.StartInfo.Arguments = " -I dummy";

        process.Start();

但是,当我注释和取消注释 WindowStyle 行时,控制台仍然显示。怎么了?

4

3 回答 3

2

尝试以下命令行开关。它记录在这里

process.StartInfo.Arguments = "-I dummy --dummy-quiet";
于 2013-11-03T20:03:03.000 回答
1

正如这里所说,只需执行以下操作:

using System.Runtime.InteropServices;

...
  [DllImport("user32.dll")]
  public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);

  [DllImport("user32.dll")]
  static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

...

     //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under.
     IntPtr hWnd = FindWindow(null, "Your console windows caption"); //put your console window caption here
     if(hWnd != IntPtr.Zero)
     {
        //Hide the window
        ShowWindow(hWnd, 0); // 0 = SW_HIDE
     }


     if(hWnd != IntPtr.Zero)
     {
        //Show window again
        ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
     }

更新:

您还应该在进程启动后添加 WaitForInputIdle:

process.Start();
process.WaitForInputIdle();
于 2013-11-03T19:15:48.023 回答
0

您可以简单地将项目属性中的输出类型更改为 Windows 应用程序。只需右键单击项目>属性>应用程序

于 2013-11-03T19:46:16.520 回答