zl程序教程

您现在的位置是:首页 >  后端

当前栏目

c#中一个进程启动另一个进程并传递参数

c#进程 一个 启动 参数 传递
2023-09-11 14:16:45 时间

1.开启进程

using System.Diagnostics;
 
ProcessStartInfo process = new ProcessStartInfo();
process.FileName = "要开启的进程路径"; 
string arg1 =  "进程参数1";
string arg2 =  "进程参数2";
process.Arguments = string.Format("{0} {1}", arg1, arg2) ;  //多个参数用空格隔开
process.WindowStyle = ProcessWindowStyle.Normal;
Process.Start(process);
2.修改要开启进程的Main函数

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)   //这里的 args 就为 {arg1,arg2} 了
{
   Application.EnableVisualStyles();
   Application.SetCompatibleTextRenderingDefault(false);
   Application.Run(new Form1(args));
}