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

首頁 > 編程 > C# > 正文

C#實(shí)現(xiàn)查殺本地與遠(yuǎn)程進(jìn)程的方法

2019-10-29 21:47:01
字體:
供稿:網(wǎng)友
這篇文章主要介紹了C#實(shí)現(xiàn)查殺本地與遠(yuǎn)程進(jìn)程的方法,可實(shí)現(xiàn)針對(duì)特定進(jìn)程的關(guān)閉操作,是C#進(jìn)程操作的一個(gè)典型應(yīng)用,需要的朋友可以參考下
 

本文實(shí)例講述了C#實(shí)現(xiàn)查殺本地與遠(yuǎn)程進(jìn)程的方法。分享給大家供大家參考。

具體實(shí)現(xiàn)方法如下:

 

復(fù)制代碼代碼如下:
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);
}  
}
}

 
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙陵县| 十堰市| 伊宁市| 吉隆县| 江口县| 闸北区| 昂仁县| 东丽区| 平武县| 荣成市| 郴州市| 礼泉县| 正安县| 惠安县| 扎赉特旗| 孝昌县| 阳城县| 板桥市| 贵州省| 普洱| 柘荣县| 平昌县| 垣曲县| 镇平县| 琼结县| 麻栗坡县| 申扎县| 临桂县| 富阳市| 阜城县| 青海省| 牟定县| 舞阳县| 丰宁| 清丰县| 渭南市| 黄龙县| 南溪县| 阳信县| 肇庆市| 祁阳县|