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 ProcessKill
{
    public partial class Form1 : Form
    {
        public System.Threading.Thread myThread;
        public Form1()
        {
            InitializeComponent();
            myThread = new System.Threading.Thread(new System.Threading.ThreadStart(kill_Process));//初始化线程,执行关闭进程方法kill_Process();
            myThread.Start();
        }         private void button1_Click(object sender, EventArgs e)
        {
            GetGetProcesses();
        }
        /// <summary>
        /// 调用此方法可查看本机当前运行的所有进程
        /// </summary>
        private void GetGetProcesses()
        {
            listView1.Items.Clear();
            Process[] list = Process.GetProcesses(".");//获取本机当前运行的所有进程
            for (int i = 0; i < list.Length; i++)//循环添加进程信息
            {
                listView1.View = View.Details;//列的显示模式
                ListViewItem lvi = new ListViewItem(new string[] { list[i].ProcessName, list[i].Id.ToString(), list[i].PrivateMemorySize64.ToString() });
                listView1.Items.Add(lvi);
            }
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {         }
        /// <summary>
        /// 关闭进程
        /// </summary>
        void kill_Process()
        {
            var killlist = System.Configuration.ConfigurationManager.AppSettings["killname"].ToString().Split(',');//获取app.cong中设置的需要关闭的进程名称
            Process[] list = Process.GetProcesses(".");//获取本机当前运行的所有进程
            foreach (var item in killlist)//遍历查看进程是否存在
            {
                foreach (Process pr in list)
                {
                    if (item == pr.ProcessName)
                    {
                        pr.Kill();
                    }
                }
            }
            //Application.Exit();
            System.Environment.Exit(System.Environment.ExitCode);//关闭自身进程
        }         private void button2_Click(object sender, EventArgs e)
        {
            kill_Process();
            GetGetProcesses();
        }         private void Form1_Load(object sender, EventArgs e)
        {
        }
    }
}

c# winfrom应用程序关闭任务管理器中的进程的更多相关文章

  1. 【Hook技术】实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展

    [Hook技术]实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展 公司有个监控程序涉及到进程的保护问题,需要避免用户通过任务管理器结束掉监控进程,这里使用 ...

  2. WinForm程序关闭窗体后杀死进程

    调用this.Close();后监听Browser_FormClosed加作处理 this.FormClosed += new System.Windows.Forms.FormClosedEvent ...

  3. C++获取Windows7 32位系统中所有进程名(类似于任务管理器中的进程)

    代码是网上查找资料,然后自己调试,修改之后可以运行. 系统:win7 32位,VS2008 ------------------------------------------------------ ...

  4. windows上,任务管理器中,进程命令行太长怎么办

    一.前言 在windows上,有时候需要查看进程命令行,但是有的进程的命令行太长了,很难看全 此时,可以使用下面的方法解决(红框改为自己要查看的进程即可): C:\Users\Gaoyu>wmi ...

  5. Windows Server 2008 R2服务器内存使用率过高,但与任务管理器中进程占用内存和不一致

    系统环境: Windows Server 2008 R2 + Sql Server 2008 R2   问题描述: Windows Server 2008 R2系统内存占用率过大,而在任务管理器中各进 ...

  6. C# 杀掉系统中的进程

    杀掉系统进程之前首先要知道进程名称(说了句废话),这里要注意在任务管理器中的进程名称不一定是真实的名称.打个比方,我们开启一个"记事本",任务管理器中进程名称为"记事本& ...

  7. 【转】 VC++ 关闭程序后任务管理器进程中进程仍然存在的解决方法

    转载出处:http://blog.csdn.net/zac_sian/article/details/50809084 可以从以下两个方面进行查找! 1.程序开启了进程,进程中使用了while(1), ...

  8. win7或win2008系统中,出现【已停止工作,联机检查解决方案并关闭该程序,关闭程序】解决方法!

    win7或win2008系统中,出现[已停止工作,联机检查解决方案并关闭该程序,关闭程序]解决方法! 经过摸索,点击[控制面板]-[操作中心]-[更改操作中心设置]-[问题报告设置]-[从不检查解决方 ...

  9. 是什么在.NET程序关闭时阻碍进程的退出?

    在平时使用软件或是.NET程序开发的过程中,我们有时会遇到程序关闭后但进程却没有退出的情况,这往往预示着代码中有问题存在,不能正确的在程序退出时停止代码执行和销毁资源.这个现象有时并不容易被察觉,但在 ...

随机推荐

  1. 在AE中通过指定中心点和半径画圆

    /// <summary>/// 通过指定的中心点.半径画圆/// </summary>/// <param name="pLayer">要画的 ...

  2. (easy)LeetCode 223.Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  3. [HDU 5113] Black And White (dfs+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5113 题目大意:给你N*M的棋盘,K种颜色,每种颜色有c[i]个(sigma(c[i]) = N*M) ...

  4. C - Fractal(3.4.1)

    Description A fractal is an object or quantity that displays self-similarity, in a somewhat technica ...

  5. Android——主流分辨率

    VGA:480*640 QVGA:240*320 HVGA:320*480 WVGA:480*800 FWVGA:480*854 IntelHaxm.exe  模拟器加速器

  6. NSArray、NSMutableArray基本用法

    NSArray.NSMutableArray基本用法 一.基本操作 初始化方法:1.init返回一个空数组 2.initWithArray从已有数组初始化 3.initWithContentsOfFi ...

  7. 常用的mysql操作命令

    1.[修改密码] 进入mysql中,使用命令:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('新密码'); 2.[授权] GRANT SELECT, I ...

  8. opencv编程解决warning C4003: “max”宏的实参不足

    忘了把程序出错的代码附上了,运行修改好的程序才发现的.只好把问题的代码大致写一下了: warning C4003: “min”宏的实参不足 error C2589: “(”:“::”右边的非法标记 e ...

  9. nginx+lua+redis初体验

    1.下载nginx.lua.redis nginx下载地址 wget  http://nginx.org/download/nginx-1.8.0.tar.gz lua下载地址 wget http:/ ...

  10. -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

    在有全屏侧滑的情况下,页面上有个slider需要左右滑动的时候,经常在滑动slider的时候页面也跟着滑动                解决办法一:关闭当前页面的全屏侧滑,开启系统侧滑   self ...