How to use ::TerminateProcess to terminate a process?
I only know the HWND as an input, first I use GetWindowThreadProcessId to get the process ID. But then how can I convert the process ID as the first input parameter of TerminateProcess which is HANDLE?
Re: How to use ::TerminateProcess to terminate a process?
Originally Posted by fantasy1215
I only know the HWND as an input, ...
But then how can I convert the process ID as the first input parameter of TerminateProcess which is HANDLE?
Did you read about using TerminateProcess in MSDN?
Doesn't any "clean" way to close a process work?
If the HWND you refer to is the handle of the main window - why not just PostMessage WM_CLOSE to it?
Re: How to use ::TerminateProcess to terminate a process?
Originally Posted by VictorN
Did you read about using TerminateProcess in MSDN?
Doesn't any "clean" way to close a process work?
If the HWND you refer to is the handle of the main window - why not just PostMessage WM_CLOSE to it?
It's kind of you to remind me of closing the process in a 'clean' way. Because the HWND is not the main window of the process, so I have to use TerminateProcess.
So I should use the code below to TerminateProcess? for I'm not sure. Thanks.
Re: How to use ::TerminateProcess to terminate a process?
Originally Posted by fantasy1215
It's kind of you to remind me of closing the process in a 'clean' way. Because the HWND is not the main window of the process, so I have to use TerminateProcess.
Not really. Given a window handle use GetWindowThreadProcessID to retrieve its processId. From there you can use the ModuleTest code in the following link to politely close the process.
Bookmarks