C#實(shí)現(xiàn)查殺本地與遠(yuǎn)程進(jìn)程的方法
更新時(shí)間:2014年12月09日 10:10:24 投稿:shichen2014
這篇文章主要介紹了C#實(shí)現(xiàn)查殺本地與遠(yuǎn)程進(jìn)程的方法,可實(shí)現(xiàn)針對特定進(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);
}
}
}
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#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- 如何在C# 中查找或結(jié)束程序域中的主、子進(jìn)程
- C#操作windows系統(tǒng)進(jìn)程的方法
- C#操作進(jìn)程的方法介紹
- C#獲取所有進(jìn)程的方法
- C#中進(jìn)程的掛起與恢復(fù)
- C#實(shí)現(xiàn)啟動(dòng),關(guān)閉與查找進(jìn)程的方法
- C#實(shí)現(xiàn)關(guān)閉其他程序窗口或進(jìn)程代碼分享
- C#實(shí)現(xiàn)強(qiáng)制關(guān)閉當(dāng)前程序進(jìn)程
- C#關(guān)閉指定名字進(jìn)程的方法
- C#操作windows系統(tǒng)進(jìn)程的方法
- C#結(jié)束進(jìn)程及子進(jìn)程
相關(guān)文章
使用Nopcommerce為商城添加滿XX減XX優(yōu)惠券功能
中秋國慶節(jié)眼看到跟前了,很多商城都借此機(jī)會搞促銷活動(dòng),什么滿200減80送優(yōu)惠券等活動(dòng),基于后臺程序是怎么實(shí)現(xiàn)的呢?下面腳本之家小編帶領(lǐng)大家一起學(xué)習(xí)吧2015-09-09
C#編程實(shí)現(xiàn)對象與JSON串互相轉(zhuǎn)換實(shí)例分析
這篇文章主要介紹了C#編程實(shí)現(xiàn)對象與JSON串互相轉(zhuǎn)換的方法,結(jié)合實(shí)例分析了在DoNet2.0與Donet3.5環(huán)境下實(shí)現(xiàn)對象與JSON轉(zhuǎn)換的相關(guān)技巧,需要的朋友可以參考下2015-11-11
深入Resource實(shí)現(xiàn)多語言支持的應(yīng)用詳解
本篇文章是對Resource實(shí)現(xiàn)多語言支持的應(yīng)用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Unity通過UGUI的Slider調(diào)整物體顏色
這篇文章主要為大家詳細(xì)介紹了Unity通過UGUI的Slider調(diào)整物體顏色,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02
C#中GraphicsPath的Flatten方法用法實(shí)例
這篇文章主要介紹了C#中GraphicsPath的Flatten方法,實(shí)例分析了Flatten方法的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06

