Solved

Processes

Posted on 2004-09-23
4
216 Views
Last Modified: 2010-04-15
Good morning, all,

In a console application, how would I go about listing all the processes currently running by pID, and then terminating a process by pID?  The more info the better, I am *Very* new at this!  Thanks in advance!

Regards,
Tony
0
Comment
Question by:fattumsdad
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 12134834
To 'Kill' (Terminate) a Process by PID use:

  int pid = ...;
  System.Diagnostics.Process process = System.Diagnostics.Process.GetProcessById(pid);
  process.Kill();
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 500 total points
ID: 12134864
To GET the processes you can use this:

  System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
  foreach(System.Diagnostics.Process process in processes)
  {
    string processName = process.ProcessName;
    int processId = process.Id;
  }
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12135372
eternal,

How do I actually display the processes in the console?  I put the above code (to get processes) and it compiles / runs fine...  but just gives me  a "press any key to continue".  I tried adding Console.WriteLine(processName, processID); to no avail.  Any suggestions? :)
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12135421
Nevermind!  Got it working!  Thanks for the help!
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to read json value 2 49
Video Player 2017 5 22
.NET 2008 VB and C# 6 27
transaction in asp.net, sql server 6 33
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question