如何从 VC 中终止进程++
我正在使用 VC++ 编译器,我想知道如何终止进程。有没有什么功能.
我尝试使用 TerminateProcess();但我做不到...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道你到底想做什么,但你必须知道
TerminateProcess()
只是杀死进程而不给他正确关闭的机会。您可能希望首先向应用程序发送一条
WM_CLOSE
消息,然后,如果它没有响应,则使用TerminateProcess()
终止它。多布斯博士在此处发表了一篇精彩文章(带有示例)。
您可能想看一下。
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 withTerminateProcess()
.Dr Dobbs has a great article (with samples) just here.
You might want to take a look.
只是为了确保您做得正确:
OpenProcess
从进程 ID 获取进程句柄(请求PROCESS_TERMINATE
访问权限)TerminateProcess
这个句柄这种方法究竟出了什么问题?
Just to make sure you did it right:
OpenProcess
to get the process handle from a process ID (requestingPROCESS_TERMINATE
access rights)TerminateProcess
on this handleWhat exactly went wrong with this approach?
TerminateProcess
需要PROCESS_TERMINATE
权限。如果您从OpenProcess
获取进程句柄,则 dwDesiredAccess 参数必须至少包含PROCESS_TERMINATE
。如果您尝试终止提升的进程,那么您的应用程序(执行终止操作的应用程序)也必须提升。
您从
GetLastError()
收到什么错误代码?TerminateProcess
requires thePROCESS_TERMINATE
right. If you're getting the process handle fromOpenProcess
, then the dwDesiredAccess parameter must at least includePROCESS_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()
?