0

I'm trying to create a C++ program which ends a process. So starting from scratch, I'm not too sure which direction I should be heading? I mean based on the research I've done the solution involves these steps (let me know if it's incorrect logic):

  1. Get process name (in my case its always the same one)

  2. Iterate through all processes and find matching name (assuming this process has a unique name)

  3. Get the id and terminate it

As I mentioned I don't have to worry about checking for duplicate process names since its assumed to be unique, but now I need guidance on what sort of library, classes etc I should be looking at?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
MrSSS16
  • 449
  • 3
  • 7
  • 21
  • Sorry forgot to mention that this is purely on a windows OS – MrSSS16 Sep 14 '12 at 12:18
  • I believe that is going to be very OS specific. On windows you want something like http://stackoverflow.com/questions/7956519/win32-api-how-to-kill-processes-by-name – stonemetal Sep 14 '12 at 12:21

2 Answers2

0

Use the TerminateProcess function.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
0

See EnumProcesses and research Handles to processes.

Pass an empty array of type pIDs to EnumProcesses, it will fill it up with the pID of all currently running processes so use a big array. This way, you can enumerate through all running processes.

Use OpenProcess to obtain the handle associated with the PID and call GetModuleFileNameEx to get its fully-qualified path to see if the one you are looking at is the one you want.

Then you can use the TerminateProcess on the handle if it is the one you want to end.

Chad Campbell
  • 321
  • 1
  • 9