views:

140

answers:

3

Am using VC++ compiler i want to know how to kill a process. is there any functions.

i tried with TerminateProcess(); but i couldn't do...

A: 

TerminateProcess requires the PROCESS_TERMINATE right. If you're getting the process handle from OpenProcess, then the dwDesiredAccess parameter must at least include PROCESS_TERMINATE.

If you're trying to kill an elevated process, then your app (the app doing the killing) must also be elevated.

What error code are you getting from GetLastError()?

Chris Schmich
+3  A: 

I don't know exactly what you want to do but you have to know TerminateProcess() just kills the process without giving him a chance to close properly.

You might want first to send a WM_CLOSE message to the application and then, if it doesn't respond, kill it with TerminateProcess().

Dr Dobbs has a great article (with samples) just here.

You might want to take a look.

ereOn
A: 

Just to make sure you did it right:

  • Use OpenProcess to get the process handle from a process ID (requesting PROCESS_TERMINATE access rights)
  • Call TerminateProcess on this handle

What exactly went wrong with this approach?

MartinStettner