C# Windows Services 启动和结束其它进程

将exe所在的绝对路径和进程名配置到配置文件中

<add key="FilePath" value="D:ABCABCD.Console.exe"/>
<add key="ProcessName" value="ABCD.Console"/>

代码如下:/// <summary>/// 进程名/// </summary>

private Process dataCenterProcess;
// 启动
{
this.dataCenterProcess = new Process(); this.dataCenterProcess.StartInfo.FileName = this.filePath; this.dataCenterProcess.StartInfo.RedirectStandardInput = true; this.dataCenterProcess.StartInfo.RedirectStandardOutput = true; this.dataCenterProcess.StartInfo.CreateNoWindow = true; this.dataCenterProcess.StartInfo.UseShellExecute = false; this.dataCenterProcess.Start();
}
// 结束
{
this.dataCenterProcess.Close(); Process[] processes = Process.GetProcessesByName(this.processName); foreach (Process p in processes) {   p.Kill();   p.Close(); }
}
原文地址:https://www.cnblogs.com/mtsl/p/4231600.html