Solved

Processes

Posted on 2004-09-23
4
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now