通过以下代称,即可实现用c#对一个外部程序的开启和关闭
命名空间
using System.Diagnostics;
Process p = new Process();
p.StartInfo.FileName = @"D:\Company\WCSServer.exe";
//进程工作的启动目录
p.StartInfo.WorkingDirectory = @"D:\Company";
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
//启动程序
p.Start();
//等待程序执行完退出进程
//p.WaitForExit();
p.Close();
//获取系统进程信息
var pro = Process.GetProcesses();
foreach (var item in pro)
{
string proName = item.ProcessName;
if (proName.Contains("WCS"))
{
//关闭进程
item.Kill();
}
}