《2022年C#进程管理源代码 .pdf》由会员分享,可在线阅读,更多相关《2022年C#进程管理源代码 .pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、实现的界面 : 1.Load 事件代码 : private void 刷新 SToolStripMenuItem_Click(object sender, EventArgs e) lvprocess.Items.Clear(); Process ps = Process.GetProcesses(); int processnumber = 0; foreach (Process p in ps) processnumber += 1; ListViewItem lv = new ListViewItem(processnumber.ToString(); lv.SubItems.Add(p
2、.ProcessName.ToString(); lv.SubItems.Add(p.Id .ToString (); try lv.SubItems.Add(p.MainModule.FileName.ToString(); catch 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - try FileVersionInfo finfo = p.MainModule.FileVersionInfo; lv.SubItems.Ad
3、d(finfo.CompanyName.ToString(); catch lv.SubItems.Add(); lvprocess.Items.Add(lv); lblprocesscount.Text = 当 前 进 程 数 : +lvprocess.Items.Count.ToString()+ ; 2.结束进程事件代码 : private void 结束进程ToolStripMenuItem_Click(object sender, EventArgs e) try foreach (ListViewItem p in lvprocess.SelectedItems) try int
4、processid = Convert.ToInt32(p.SubItems2.Text); Process pro = Process.GetProcessById(processid); pro.CloseMainWindow(); pro.WaitForExit(10); if (!pro.HasExited) pro.Kill(); catch catch 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - 刷新 cmenu
5、process.PerformClick(); 3.强制结束进程事件代码private void 强制结束进程ToolStripMenuItem_Click(object sender, EventArgs e) try foreach (ListViewItem p in lvprocess.SelectedItems) try int processid = Convert.ToInt32(p.SubItems2.Text); Process pro = Process.GetProcessById(processid); pro.Kill(); catch catch 刷新 cmenup
6、rocess.PerformClick(); 4. 隐藏系统进程 PID 小于 1024 事件代码private void 隐藏系统进程PID小于 1024ToolStripMenuItem_Click(object sender, EventArgs e) lvprocess.Items.Clear(); Process ps = Process.GetProcesses(); int processnumber = 0; foreach (Process p in ps) if (p.Id = 1024) processnumber += 1; ListViewItem lv = new
7、ListViewItem(processnumber.ToString(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - lv.SubItems.Add(p.ProcessName.ToString(); lv.SubItems.Add(p.Id.ToString(); try lv.SubItems.Add(p.MainModule.FileName.ToString(); catch try FileVersionInf
8、o finfo = p.MainModule.FileVersionInfo; lv.SubItems.Add(finfo.CompanyName.ToString(); catch lvprocess.Items.Add(lv); 5. 在线搜索进程事件代码private void 在线搜索进程ToolStripMenuItem_Click(object sender, EventArgs e) try foreach (ListViewItem searchp in lvprocess.SelectedItems) Process.Start( http:/ + searchp.SubIt
9、ems1.Text + &ch=&tn=sitehao123&bar=); catch 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 7 页 - - - - - - - - - 6. 在线分析进程事件代码private void 在线分析进程ToolStripMenuItem_Click(object sender, EventArgs e) try Process.Start(http:/www.virscan.org/); catch 7. 导出为 txt 文件事件
10、代码private void 导出为 txt 文件 ToolStripMenuItem_Click(object sender, EventArgs e) StreamWriter sw = File.CreateText( 进程信息 .txt); try foreach (ListViewItem item in lvprocess.Items) sw.Write(item.SubItems0.Text.ToString() + + item.SubItems1.Text.ToString() + +item.SubItems2.Text.ToString() + ); try sw.Wri
11、teLine ( item.SubItems3.Text.ToString() + +item.SubItems4.Text.ToString(); catch sw.Close(); Process.Start(进程信息 .txt); catch 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 7 页 - - - - - - - - - 8. 隐藏微软进程文件厂商为微软事件代码private void 隐藏微软进程文件厂商为微软ToolStripMenuItem_Cli
12、ck(object sender, EventArgs e) lvprocess.Items.Clear(); Process ps = Process.GetProcesses(); int processnumber = 0; foreach (Process p in ps) string filemake = ; try FileVersionInfo finfo = p.MainModule.FileVersionInfo; filemake =finfo.CompanyName.ToString(); catch filemake = ; if (filemake != Micro
13、soft Corporation) processnumber += 1; ListViewItem lv = new ListViewItem(processnumber.ToString(); lv.SubItems.Add(p.ProcessName.ToString(); lv.SubItems.Add(p.Id.ToString(); try lv.SubItems.Add(p.MainModule.FileName.ToString(); catch lv.SubItems.Add(filemake ); lvprocess.Items.Add(lv); 名师资料总结 - - -精
14、品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 7 页 - - - - - - - - - 9. 定位所在文件夹事件代码private void 定位所在文件夹ToolStripMenuItem_Click(object sender, EventArgs e) foreach (ListViewItem item in bootlst.SelectedItems) if (item.Selected) try FileInfo finfo = new FileInfo(item.SubItems
15、2.Text); string temp = finfo.DirectoryName; Process.Start(temp); catch 10.要导入的命名空间using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Win32; using System.Diagnostics; using System.IO; using System.Management; using System.Runtime.InteropServices; using System.Threading; 爱优制作 2011 年 8 月 31 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -
限制150内