(Process class under the System.Diagnostics namespace)
"1" gets all processes on the local machine
1 progress[] myprogress = progress.getprocesses ();
"2" gets the process of the name specified on the local computer
1 process[] myprocess = Process.getprocessesbyname (" process name ");
Example: 1 process[] myprocess = Process = Process.getprocessbyneme ("notepad++" );
"3" gets all the processes of the remote computer
1 process[] myprocess = process.getprocesses (remotemachinename);
Where remotemachinename can be a remote computer name, or it can be a remote computer IP address
"4" gets the process with the name specified on the remote computer
1 process[] myprocess = Process.getprocessesbyname (ProcessName, remotemachinename);
Where ProcessName is a process name that does not include the. exe or path name
Example:
1 usingSystem;2 usingSystem.Diagnostics;3 4 namespaceprocesslocal5 {6 class Program7 {8 Static voidMain (string[] args)9 {Tenprocess[] Myprocess =process.getprocesses (); OneConsole.Write ("Process Id\t"); AConsole.Write ("process name \ t"); -Console.Write ("physical memory \ t"); -Console.Write ("startup time \ t"); the //console.write ("File path"); - Console.WriteLine (); - foreach(Process Pinchmyprocess) - { +Console.Write (P.id +"\ t"); -Console.Write (P.processname +"\ t"); +Console.Write (string. Format ("{0:###,# #0.00}MB", P.workingset64/1024.0f/1024.0f) +"\ t"); A //Some processes cannot get boot time and file name information, so use Try/catch at Try - { -Console.Write (String.Format ("{0}", P.starttime) +"\ t"); - //Console.Write (p.mainmodule.filename + "T"); - } - Catch in { - //Console.Write ("\ t"); toConsole.Write ("\ t"); + } - Console.WriteLine (); the * } $ Panax Notoginseng Console.read (); - } the } +}
Processes management (Process Class)