开发者

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 (requesting PROCESS_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()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜