• 大小: 52KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: 其他
  • 标签: 进程监控  

资源简介

这个程序是用来监控进程执行情况的,例如我在配置文件里面写了HQMSJob.exe,那程序就是监控这个程序的执行情况,打开多过两个的就会被关闭,如果全部关闭进程监控程序就会重启要监控的进程(程序)

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace ProcessMonitor
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private string filePath = Application.StartupPath + @“\xml\ExecuteEXE.xml“;
        private string executeName = string.Empty;
        private System.IO.TextWriter logWriter;

        private bool isRunning = false;
        private void timer1_Tick(object sender EventArgs e)
        {
            if (isRunning) return;

            isRunning = true;

            Process[] ps = Process.GetProcessesByName(executeName);

            if (ps.Length > 1)
            {
                int count = ps.Length;
                foreach (Process p in ps)
                {
                    count--;
                    p.Kill();
                    if (count == 1) break;
                }
            }
            else if (ps.Length == 0)
            {
                Process.Start(executeName + “.exe“);
                WriteLogs(“启动“ + executeName + “.exe“);
            }

            isRunning = false;
        }

        private void frmMain_Load(object sender EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
            this.WindowState = FormWindowState.Minimized;
            this.ShowInTaskbar = false;

            executeName = string.Empty;
            xmlOperator.ReadNodeValue(filePath “ExecuteName“ ref executeName);

            this.timer1.Start();
            WriteLogs(“自动上传程序启动!“);
        }

        private void WriteLogs(string text)
        {
            //if (this.rtbLogs != null)
            //{
            //    this.rtbLogs.AppendText(text + “\n“);
            //}
            try
            {
                this.logWriter = System.IO.File.AppendText(Application.StartupPath + @“\log\monitor.log“);
                this.logWriter.WriteLine(DateTime.Now.ToString() +“  “+ text + “\n“);
                this.logWriter.Close();
            }
            catch (Exception exception)
            {
                //this.rtbLogs.AppendText(“写入日志出错(“ + DateTime.Now.ToString() + “):“ + exception.Message + “\n“);
            }
            finally
            {
                if (this.logWriter != null)
                {
                    this.logWriter.Close();
                }
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     35840  2015-09-23 00:34  ProcessMonitor\.vs\ProcessMonitor\v14\.suo

     文件      10240  2015-09-23 00:33  ProcessMonitor\bin\Debug\ProcessMonitor.exe

     文件      24064  2015-09-23 00:33  ProcessMonitor\bin\Debug\ProcessMonitor.pdb

     文件      21680  2015-09-23 00:33  ProcessMonitor\bin\Debug\ProcessMonitor.vshost.exe

     文件        490  2015-06-04 12:48  ProcessMonitor\bin\Debug\ProcessMonitor.vshost.exe.manifest

     文件         96  2015-02-10 14:58  ProcessMonitor\bin\Debug\xml\ExecuteEXE.xml

     文件       2679  2015-09-23 00:19  ProcessMonitor\frmMain.cs

     文件       1859  2015-09-23 00:13  ProcessMonitor\frmMain.Designer.cs

     文件       6008  2015-09-23 00:13  ProcessMonitor\frmMain.resx

     文件        790  2015-09-23 00:12  ProcessMonitor\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6786  2015-09-23 00:33  ProcessMonitor\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1635  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.csproj.FileListAbsolute.txt

     文件        849  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.csproj.GenerateResource.Cache

     文件       1740  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.csprojResolveAssemblyReference.cache

     文件      10240  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.exe

     文件        180  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.frmMain.resources

     文件      24064  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.pdb

     文件        180  2015-09-23 00:33  ProcessMonitor\obj\Debug\ProcessMonitor.Properties.Resources.resources

     文件       3584  2015-09-23 00:12  ProcessMonitor\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       4131  2015-09-23 00:33  ProcessMonitor\ProcessMonitor.csproj

     文件        994  2015-09-23 00:31  ProcessMonitor\ProcessMonitor.sln

     文件        497  2015-02-10 11:42  ProcessMonitor\Program.cs

     文件       1368  2015-02-10 11:42  ProcessMonitor\Properties\AssemblyInfo.cs

     文件       2856  2015-09-23 00:04  ProcessMonitor\Properties\Resources.Designer.cs

     文件       5612  2015-02-10 11:42  ProcessMonitor\Properties\Resources.resx

     文件       1097  2015-09-23 00:04  ProcessMonitor\Properties\Settings.Designer.cs

     文件        249  2015-02-10 11:42  ProcessMonitor\Properties\Settings.settings

     文件        267  2015-02-10 15:24  ProcessMonitor\Properties\vssver2.scc

     文件       4562  2015-02-10 14:55  ProcessMonitor\xmlOperator.cs

     目录          0  2015-09-23 00:31  ProcessMonitor\.vs\ProcessMonitor\v14

............此处省略15个文件信息

评论

共有 条评论