批量结束进程 让系统加速
运行环境:Win10,其它版本的windows系统需安装.net framework 4.0
1.双击当前进程,会加入到要结束的进程列表里
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 KillProcess
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 关闭进程名含某某的进程 数组
/// </summary>
/// <param name="processName">进程名数组</param>
private static void KillProcess(string[] processName)
{
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
foreach (string pn in processName)
{
if (pn.Length < 1)
{
break;
}
if (item.ProcessName.Contains(pn))
{
item.Kill();
}
}
}
}
/// <summary>
/// 关闭进程名含某某的进程
/// </summary>
/// <param name="processName">进程名</param>
private static void KillProcess(string processName)
{
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
if (item.ProcessName.Contains(processName))
{
item.Kill();
}
}
}
//强制关闭最近打开的某个进程
private static void KillRecentProcess(string processName)
{
System.Diagnostics.Process[] Proc = System.Diagnostics.Process.GetProcessesByName(processName);
System.DateTime startTime = new DateTime();
int m, killId = 0;
for (m = 0; m < Proc.Length; m++)
{
if (startTime < Proc[m].StartTime)
{
startTime = Proc[m].StartTime;
killId = m;
}
}
if (Proc[killId].HasExited == false)
{
Proc[killId].Kill();
}
}
private void DisplayProcess()
{
listBox1.Items.Clear();
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
listBox1.Items.Add(item.ProcessName);
}
listBox1.Sorted = true;
label1.Text = "当前系统进程:" + listBox1.Items.Count;
}
private void Form1_Load(object sender, EventArgs e)
{
DisplayProcess();
KillProcess(Settings1.Default.kill.Split(','));
textBox1.Text = Settings1.Default.kill;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Settings1.Default.kill=textBox1.Text;
Settings1.Default.Save();
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
string str = ((ListBox)sender).SelectedItem.ToString();
((ListBox)sender).Items.Remove(((ListBox)sender).SelectedItem);
label1.Text = "当前系统进程:" + listBox1.Items.Count;
KillProcess(str);
//DisplayProcess();
if (textBox1.Text == "")
{
textBox1.Text = str;
}
else
{
textBox1.Text += "," + str;
}
}
private void label1_Click(object sender, EventArgs e)
{
DisplayProcess();
}
}
}