首页 > Windows开发 > 详细

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

时间:2015-01-18 13:02:22      阅读:265      评论:0      收藏:0      [点我收藏+]

将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 启动和结束其它进程

原文:http://www.cnblogs.com/mtsl/p/4231600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!