資源簡介
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個文件信息
- 上一篇:東南大學數電數字電路實驗ppt課件
- 下一篇:計算機視覺中的數學方法(吳福朝)
評論
共有 條評論