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

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

<add key="FilePath" value="D:\ABC\ABCD.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(); }
}

 

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

上一篇:C# Newtonsoft.Json JObject 操作


下一篇:Oracle 11g 数据库的部署