1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#で別EXEをパラメータ渡しで実行する

Posted at

1. はじめに

  • C#で別ソリューションのEXEを起動したい
  • 起動する時にパラメータ渡しで必要な情報を連携したい

2. 開発環境

  • C#
  • .NET 6
  • Visual Studio 2022
  • Windows 11

3. ソースコード

// 外部EXEを起動する
private void Button1_Click(object sender, EventArgs e)
{
    // 外部EXEを起動する
    var info = new ProcessStartInfo("notepad")
    {
        // コマンドラインパラメータを指定する
        ArgumentList =
        {
            @"C:\\tmuninst.ini"
        }
     };
     Process? p = Process.Start(info);

     if (p != null)
     {
          // 別EXEが終了するまで待つ場合
          p.WaitForExit();
          MessageBox.Show("メモ帳が終了しました" + "\r\n" +
               "StartTime:" + "\r\n" + p.StartTime + "\r\n" +
               "DateTime" + p.ExitTime + "\r\n" +
               "TotalProcessorTime:" + p.TotalProcessorTime
          );

          // 別EXEを強制終了する場合
          // System.Threading.Thread.Sleep(5000);
          // p.Kill();

           // 別EXEからプログラムの終了コードを受け取る場合
           int code = p.ExitCode;
     }
}

4. 参考文献

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?