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");
}
}
}
作者:(⊙_⊙)★燚♂靈惢★空间
出处: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");
}
}
}
相关文章推荐
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- C#Winform打开窗体的几种方法、注意事项的总结
- C# winform打开Excel文档的方法总结!
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- 总结C# ----后台弹出窗体和打开网页的不同方法,以及关闭网页的方法.
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- C#实现让程序只能打开一个实例(总结3方法)(转)
- C#实现让程序只能打开一个实例(总结3方法)(转)
- C# 两种启动bat文件方法的区别——关键在于进程的工作目录
- C#将Word转换成PDF方法总结(基于Office和WPS两种方案)
- c# 读取其他程序正打开的文件的时“正由另一进程使用,因此该进程无法访问该文件。"的问题解决方法
- C# 判断窗体是否打开 如果打开激活窗体 两种方法
- [C#] 计算大文件的MD5的两种方式(直接调用方法计算,流计算-适用于大文件)
- 读<<CLR via C#>>总结(2) 对象创建的原理和两种类型转换方法
- (转)C#操作Excel(创建、打开、读写、保存)几种方法的总结
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
- [技巧] C#实现让程序只能打开一个实例(总结3方法)
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- C#线程进程总结(线程调用带参数的方法)