关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

云南大王-进程守护工具

发布时间:2020-04-13 00:00:00
进程守护工具 1.写在前面 经常写一些服务程序,有时要监测服务程序的运行状态,所以就做了一个进程守护工具。 2.分析 通过Process.GetProcessesByName(ProcessName),获得指定进程列表。 用Process.MainModule.FileName来判断程序是否运行。 3.程序实现 下面将贴出实现该程序的主要代码。 /// /// 判断进程是否正在运行,可通过程序全路径 /// /// 进程名称 /// 进程全路径 public static bool GetProcess(string ProcessName, string FileName = null) { Process[] ps = Process.GetProcessesByName(ProcessName); foreach (Process p in ps) { if (string.IsNullOrEmpty(FileName))//无值 { return true; } else//指定 { if (string.Equals(p.MainModule.FileName, FileName, StringComparison.CurrentCultureIgnoreCase)) { return true; } } } return false; } /// /// 启动程序 /// /// 程序路径 public static bool RestartProcess(string FileName) { try { Process.Start(FileName); return true; } catch (Exception ex) { Log4Net.LogInfo(string.Format("启动程序异常:{0}", ex.Message)); return false; } } View Code 4.程序界面 5.功能 1、设置程序监测列表。2、支持同一个程序不同运行路径的监测。3、界面日志和文件日志。 下载地址:https://pan.baidu.com/s/1y1ApRjcLoDdKssXsVOQfCQ 提取码:gder 

/template/Home/Zkeys/PC/Static