资源简介

1将代码生成文件exe;exe.config,拷贝到要守护软件安装目录下, 2修改MonitorClient.exe.config的key为name的value值为要守护软件的名称, 3以管理员身份运行MonitorClient.exe 4即可自动启动要守护的软件 5右键菜单可设置开机启动

资源截图

代码片段和文件信息

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.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Configuration;
using Microsoft.Win32;
namespace MonitorClient
{
    public partial class MainForm : Form
    {
        Thread threa;
        public MainForm()
        {
            InitializeComponent();
        }

        [DllImport(“User32.dll“ EntryPoint = “SendMessage“)]

        private static extern int SendMessage(IntPtr wnd int msg IntPtr wP IntPtr lP);

        private void MainForm_Load(object sender EventArgs e)
        {
            threa = new Thread(ProcessState);
            threa.IsBackground = true;
            threa.Start();
            this.Hide();
        }

        public void ProcessState()
        {           
            while (true)
            {
                try
                {
                    Process[] pros = Process.GetProcesses();
                    string name = ConfigurationManager.AppSettings[“name“].ToString();
                    Process process = pros.Where(n => n.ProcessName == name).FirstOrDefault();
                    if (process == null)
                    {
                        string strPath = Application.StartupPath + “\\“ + name + “.exe“;
                        Process.Start(strPath);
                        //string strPath = ConfigurationManager.AppSettings[“path“].ToString();
                        //pros = Process.GetProcesses();
                        //Process proce = pros.Where(n => n.ProcessName == name).FirstOrDefault();
                       
                        //if (proce != null)
                        //{
                        //    IntPtr hWnd = proce.MainWindowHandle;
                        //    int data = Convert.ToInt32(“1“);
                        //    SendMessage(hWnd 0x0100 (IntPtr)data (IntPtr)0);
                        //}
                    }
                }
                catch (Exception)
                { 
                }
                Thread.Sleep(3000);
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender EventArgs e)
        {
            Application.Exit();
        }

        private void 关机自动启动ToolStripMenuItem_Click(object sender EventArgs e)
        {
            string KJLJ = Application.ExecutablePath;
            if (!System.IO.File.Exists(KJLJ))//判断指定文件是否存在
                return;
            string newKJLJ = KJLJ.Substring(KJLJ.LastIndexOf(“\\“) + 1);
                RegistryKey Rkey =
                Registry.LocalMachine.OpenSubKey(“SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run“ true);
            if (Rkey == null)
                Rkey = Registry.LocalMachine.CreateSubKey(“SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\R

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

     文件        164  2013-04-25 11:28  MonitorClient\MonitorClient\App.config

     文件      21238  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Debug\cargocollective.ico

     文件      16958  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Debug\cargocollective64.ico

     文件      21238  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Release\cargocollective.ico

     文件      16958  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Release\cargocollective64.ico

     文件      28160  2013-04-25 11:45  MonitorClient\MonitorClient\bin\Release\MonitorClient.exe

     文件        164  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Release\MonitorClient.exe.config

     文件      22016  2013-04-25 11:45  MonitorClient\MonitorClient\bin\Release\MonitorClient.pdb

     文件      11600  2013-07-05 16:20  MonitorClient\MonitorClient\bin\Release\MonitorClient.vshost.exe

     文件        164  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Release\MonitorClient.vshost.exe.config

     文件        490  2010-03-17 22:39  MonitorClient\MonitorClient\bin\Release\MonitorClient.vshost.exe.manifest

     文件      19403  2013-04-25 11:28  MonitorClient\MonitorClient\bin\Release\Release.rar

     文件      21238  2013-04-25 11:28  MonitorClient\MonitorClient\cargocollective.ico

     文件      16958  2013-04-25 11:28  MonitorClient\MonitorClient\cargocollective64.ico

     文件       3271  2013-04-25 11:42  MonitorClient\MonitorClient\MainForm.cs

     文件       4265  2013-04-25 11:28  MonitorClient\MonitorClient\MainForm.Designer.cs

     文件      31966  2013-04-25 11:28  MonitorClient\MonitorClient\MainForm.resx

     文件       4683  2013-04-25 11:28  MonitorClient\MonitorClient\MonitorClient.csproj

     文件       4440  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7050  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        486  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        958  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\GenerateResource.write.1.tlog

     文件       1451  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\MonitorClient.csproj.FileListAbsolute.txt

     文件      29184  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\MonitorClient.exe

     文件      17536  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\MonitorClient.MainForm.resources

     文件      24064  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\MonitorClient.pdb

     文件        180  2013-04-25 11:28  MonitorClient\MonitorClient\obj\x86\Debug\MonitorClient.Properties.Resources.resources

     文件       4440  2013-07-05 16:20  MonitorClient\MonitorClient\obj\x86\Release\DesignTimeResolveAssemblyReferences.cache

     文件       6807  2013-05-16 10:40  MonitorClient\MonitorClient\obj\x86\Release\DesignTimeResolveAssemblyReferencesInput.cache

     文件        354  2013-04-25 11:45  MonitorClient\MonitorClient\obj\x86\Release\GenerateResource.read.1.tlog

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

评论

共有 条评论