It is easy to search for/sort, but the system command ntsd.exe can be used as a result. For detailed usage, see the following code:
Using system;
Using system. diagnostics;
Using system. Windows. forms;
Namespace processdemo
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void form1_load (Object sender, eventargs E)
{
This. linklabel1.links. Add (0, linklabel1.text. length, "http://yjmyzz.cnblogs.com /");
}
Private void linklabel1_linkclicked (Object sender, linklabellinkclickedeventargs E)
{
This. linklabel1.links [linklabel1.links. indexof (E. Link)]. Visited = true;
String target = E. Link. linkdata as string;
If (target! = NULL & target. startswith ("http ://"))
{
Process. Start (target );
}
}
/// <Summary>
/// List all accessible processes
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void btnlist_click (Object sender, eventargs E)
{
Process [] processes;
Processes = process. getprocesses ();
String STR = "";
Foreach (PROCESS p in processes)
{
Try
{
STR = P. processname;
This. lst1.items. add ("name:" + P. processname + ", start time:" + P. starttime. toshorttimestring () + ", process ID:" + P. id. tostring ());
}
Catch (exception ex)
{
This. lst1.items. Add (ex. Message. tostring (); // some system processes prohibit access, so add Exception Processing.
}
}
}
Private void btnfind_click (Object sender, eventargs E)
{
Txtfind. Text = txtfind. Text. Trim (). tolower ();
If (txtfind. Text. length> 0)
{
Process [] ARRP = process. getprocesses ();
Foreach (PROCESS p in ARRP)
{
Try
{
If (P. processname. tolower () = txtfind. Text)
{
MessageBox. Show (txtfind. Text + "found, PID is" + P. Id. tostring ());
Return;
}
}
Catch {}
}
MessageBox. Show ("this process is not found. Please check the input! ");
}
}
Private void btnkill_click (Object sender, eventargs E)
{
Txtfind. Text = txtfind. Text. Trim (). tolower ();
Int pid =-1;
If (txtfind. Text. length> 0)
{
Process [] ARRP = process. getprocesses ();
Foreach (PROCESS p in ARRP)
{
Try
{
If (P. processname. tolower () = txtfind. Text)
{
PID = P. ID;
Break;
}
}
Catch {}
}
If (PID! =-1)
{
Runcmd ("ntsd-C q-P" + PID );
}
}
}
/// <Summary>
/// Run the doscommand
/// Dos process shutdown command (ntsd-C q-p pid) PID is the process ID
/// </Summary>
/// <Param name = "command"> </param>
/// <Returns> </returns>
Public String runcmd (string command)
{
PROCESS p = new process ();
P. startinfo. filename = "cmd.exe ";
P. startinfo. Arguments = "/C" + command;
P. startinfo. useshellexecute = false;
P. startinfo. redirectstandardinput = true;
P. startinfo. redirectstandardoutput = true;
P. startinfo. redirectstandarderror = true;
P. startinfo. createnowindow = true;
P. Start ();
Return P. standardoutput. readtoend ();
}
}
}
In addition, ntsd.exe is available for Versions later than Windows Vista (including Windows Vista download ).
Http://files.cnblogs.com/yjmyzz/ntsd.rar