. NET encapsulates the process management very well, by using the System.Diagnostics.Process.GetProcesses () method to get an array of processes within the system. Enumeration allows you to get all the processes within your system (see more than the process browser that Windows takes).
The ProcessName property gets the prefix of the filename, Notepad, and does not contain the following. exe.
To get more information, you need to get an array of modules properties, but not every process can get the Modules property, so you must use a try ... The catch statement excludes exceptions. The first member of the array [0]. FileName contains the full file name of the executing program, equivalent to Processmodule; a member with an ordinal number greater than 0 often contains DLL information called by the program, and the result is a bit like a Trojan horse program.
The Kill () method is used to kill the process, and the killed program does not pop up a dialog box similar to the save file, and is a very cold-blooded quick hand.
The StartInfo property is used to start a new process and is not intended to retrieve a running process.
private void Btnprocess_click (object sender, System.EventArgs e)
{
System.Diagnostics.Process [ ]myps;
Myps=system.diagnostics.process.getprocesses ();
This.richTextBox1.Clear ();
foreach (System.Diagnostics.Process p in Myps)
{
if (p.id!=0)
{
String mys= "process name" +p.processname+ "ID:" +p.id.tostring ();
try//because processes are different, some processes do not contain Modules information, so try to protect
{
if (p.modules!=null)
if (p.modules.count>0)
{
System.Diagnostics.ProcessModule pm=p.modules[0];
myS+="\n Modules[0].FileName:"+pm.FileName;
myS+="\n Modules[0].ModuleName:"+pm.ModuleName;
myS+="\n Modules[0].FileVersionInfo:\n"+pm.FileVersionInfo.ToString();
if (pm.FileName.ToLower()==this.textBox1.Text.Trim().ToLower())
p.Kill();
}
}
catch
{}
finally
{
this.richTextBox1.Text += myS+"\n==========================\n";
}
}
}