欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

C#实现查杀本地与远程进程的方法

时间:2021-07-07 08:53:47|栏目:.NET代码|点击:

本文实例讲述了C#实现查杀本地与远程进程的方法。分享给大家供大家参考。

具体实现方法如下:

复制代码 代码如下:
using System;
using System.Management;
using System.Threading;
 
class xkill
{
public static void usage()
{
Console.WriteLine();
Console.WriteLine("xkill v1.0 Beta, By R&S");
Console.WriteLine("E-mail: yrwithsh@vip.sina.com");
Console.WriteLine("H-Page: Http://fz5fz.yeah.net");
Console.WriteLine();
Console.WriteLine("Usage:  xkill [ip] [account] [password] [programme] [time(s)]");
Console.WriteLine("If its the localhost,dont need account and password");
Console.WriteLine("Example: xkill 218.194.X.X administrator 123 qq.exe 60");
Console.WriteLine("         xkill 218.194.X.X administrator NULL qq.exe 60");
Console.WriteLine("         xkill 127.0.0.1 qq.exe 60 (for localhost)");
 
}
 
public static void Main(string[] args)
{
if((args.Length!=5)&&(args.Length!=3))
{
usage();
Environment.Exit(0);
}
while((args[0]=="127.0.0.1")││(args[0]=="192.168.0.1"))
{
string KillName=args[1]; 
ManagementObjectSearcher link = new ManagementObjectSearcher("SELECT * From Win32_Process");
ManagementObjectCollection Collection = link.Get();
foreach (ManagementObject Process in Collection)
{
Console.WriteLine("{0} {1}",Convert.ToString(Process["Name"]).PadRight(15),Process["ExecutablePath"]);
       if (Convert.ToString(Process["Name"])==KillName)
{
string[] Tparas = {"1"};
  Process.InvokeMethod("Terminate", Tparas);
}
 }
Console.WriteLine();
Console.WriteLine("Terminate it yet");
Thread.Sleep(Convert.ToInt32(args[2])*1000);
 }
 
try{
    do
    {
string KillName=args[3];
ConnectionOptions Conn = new ConnectionOptions();
Conn.Username =args[1];
if(args[2]=="NULL")
{
Conn.Password ="";
}
else Conn.Password =args[2];
ManagementPath p = new ManagementPath("\\"+args[0]+"\root\cimv2");  
ManagementScope ms = new ManagementScope(p,Conn);
ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher link = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection Collection = link.Get();
     Console.WriteLine("--------------------------------------------------------");
foreach (ManagementObject Process in Collection)
{
Console.WriteLine("{0}{1}",Convert.ToString(Process["Name"]).PadRight(15),Process["ExecutablePath"]);
       if (Convert.ToString(Process["Name"])==KillName)
{
string[] Tparas = {"1"};
  Process.InvokeMethod("Terminate", Tparas);
}
 
}
 
 
Thread.Sleep(Convert.ToInt32(args[4])*1000); 
 }while(true);
}
 catch(Exception exObj)
{
Console.WriteLine();
Console.WriteLine("failed!");
Console.WriteLine(exObj.Message);

}
}

 
希望本文所述对大家的C#程序设计有所帮助。

上一篇:C#文件目录操作方法汇总

栏    目:.NET代码

下一篇:C#使用Directoryinfo类获得目录信息和属性的方法

本文标题:C#实现查杀本地与远程进程的方法

本文地址:http://www.codeinn.net/misctech/154108.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有