C#源码 批量结束进程 让系统加速 参数配置保存

这是一个用于Windows系统的工具,能够批量结束指定名称的进程,通过简单操作即可实现系统资源的有效释放,适用于需要快速清理运行中进程的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

批量结束进程 让系统加速

运行环境: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();
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黄人软件

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值