您的位置:首页 > 编程语言 > C#

C#自我总结: 阻止打开任务管理器(两种方法,也适用于杀掉进程)

2012-01-23 01:36 369 查看
有不合理的地方麻烦指出,谢谢!

作者:(⊙_⊙)★燚♂靈惢★空间
出处:http://515847999.qzone.qq.com
CSDN个人主页:http://hi.csdn.net/qq515847999
本文版权归作者和广大编程爱好者共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利……

原理就是扫描任务管理器中的进程,如果检查到有taskmgr.exe的进程(任务管理器进程),就把这个进程结束了。
提示:将窗口属性ShowInTaskbar设置为false后,程序运行时就不会再任务栏显示了!
个人觉得将此方法生成独立exe后,再进行加壳运行更好点!



做一个简单的界面,反正你又看不到【因为this.Hide()】!



方法一:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Diagnostics;

namespace killtaskmgr

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }
        private void Form1_Load(object sender, EventArgs e)

        {
            this.ShowInTaskbar = false;

            this.Hide();                  //对用户隐藏控件,你压根就看不到这个程序在运行

        }
        private void Form1_Shown(object sender, EventArgs e)

        {

            timer1.Enabled = true;                                    //启用timer控件
            timer1.Interval = 400;                                     //扫描频率  

        }
        private void timer1_Tick(object sender, EventArgs e)

        {

            Process[] ps = Process.GetProcesses();

            foreach (Process item in ps)

            {

                if (item.ProcessName == "taskmgr")   

                {

                   item.Kill();

                }

            }

        }

    }

}
方法二:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Diagnostics;

namespace killtaskmgr

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }
        private void Form1_Load(object sender, EventArgs e)

        {

            this.Hide();                  //对用户隐藏控件,你压根就看不到这个程序在运行

        }
        private void Form1_Shown(object sender, EventArgs e)

        {

            timer1.Enabled = true;

            timer1.Interval = 400;

        }
        private void timer1_Tick(object sender, EventArgs e)

        {

            Process p = new Process();

            p.StartInfo.FileName = "cmd.exe";

            p.StartInfo.UseShellExecute = false;                  //这里是关键点,不用Shell启动

            p.StartInfo.RedirectStandardInput = true;             //重定向输入

            p.StartInfo.RedirectStandardOutput = true;            //重定向输出

            p.StartInfo.CreateNoWindow = true;                    //不显示窗口

            p.Start();

            p.StandardInput.WriteLine("taskkill /f /im taskmgr.exe");// 向cmd.exe输入command

            p.StandardInput.WriteLine("exit");

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐