C # tool for killing local/Remote Processes

Source: Internet
Author: User

Xkill [original]

Author: R & S
E-mail: yrwithsh@vip.sina.com
HomePage: fz5fz.yeah.net
Date: 10/04/2003

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 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 );
}
}
}

Xkill [original]

Author: R & S
E-mail: yrwithsh@vip.sina.com
HomePage: fz5fz.yeah.net
Date: 10/04/2003

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 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 );
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.