the start address is always changing for the thread also the threadid is always changing, I'm trying to kill a thread from another process how to identify the thread that I want to kill if possible i want some code examples please !
CodePudding user response:
There is nothing available to "identify" a thread externally. You can enumerate a process's threads, but all that gives you is a list of thread IDs, nothing else. So you have to "know" the specific thread ID you want ahead of time, ie if the target process gives it to you. Otherwise you are flying blind.
CodePudding user response:
You can use the function CreateToolhelp32Snapshot
to create a snapshot of a certain process, and then use the functions Thread32First
and Thread32Next
to traverse the list of all threads in that snapshot. See the following page from the official Microsoft documentation for an example:
After you have found the thread that you want to terminate, you can then open it with OpenThread
and call TerminateThread
on it.
However, before you decide to do that, I strongly suggest that you read the documentation of the function TerminateThread
(link see above). As stated in the documentation, terminating a thread is a very risky thing to do and is generally not recommended.