国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現查殺本地與遠程進程的方法

2020-01-24 02:14:58
字體:
來源:轉載
供稿:網友

本文實例講述了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("http://"+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#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长泰县| 明溪县| 北流市| 芦溪县| 横山县| 两当县| 黄大仙区| 茂名市| 贺州市| 东明县| 浦江县| 原平市| 安徽省| 永寿县| 曲阳县| 民丰县| 卢氏县| 临颍县| 云林县| 塔城市| 新丰县| 松阳县| 天等县| 花垣县| 凤城市| 辰溪县| 宁晋县| 论坛| 武山县| 乌兰县| 鞍山市| 绍兴市| 五华县| 石泉县| 河源市| 聂荣县| 田阳县| 金门县| 新丰县| 雅江县| 拉萨市|