How to kill a process from VC++
Am using VC开发者_StackOverflow社区++ compiler i want to know how to kill a process. is there any functions.
i tried with TerminateProcess(); but i couldn't do...
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.
Just to make sure you did it right:
- Use
OpenProcess
to get the process handle from a process ID (requestingPROCESS_TERMINATE
access rights) - Call
TerminateProcess
on this handle
What exactly went wrong with this approach?
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()
?
精彩评论