3

C# コンソール アプリケーションから VLC を実行しようとしていますが、実行できません。他にも同様の質問があることを知っています (たとえば、C# でコンソール ウィンドウを邪魔することなくプロセスを起動し、C# で外部コンソール アプリケーションを実行し、出力はありませんか?およびC#: 外部コンソール プログラムを 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

hereと書かれているように、次のことを行ってください。

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 に答える