I read on this blog that sysinernals uses CreateRemoteThread() to inject ExitProcess into another process to terminate it. Is it true? And, if yes, can someone show me how to do it in my Delphi application? I want to terminate the process which started my application.
I read on this blog that sysinernals uses CreateRemoteThread() to inject ExitProcess into another
Share
The question you ask here is answered on this blog post: http://private-storm.de/2009/08/11/case-terminateprocess/
This includes Delphi source code. For some reason that code enabled the
SE_DEBUG_NAMEprivilege, which is not necessary.The difficulty with this kind of approach is locating the address of
ExitProcessin the target app. The code in the article assumes that it’s at the same address as in your own process. That’s very likely true, but not always. For example, if your process is a 64 bit process and the target process is a 32 bit process then it won’t be true. Or if the target process has a base address that doesn’t allow kernel32 to load at its preferred address.Another problem is if your process is 32 bit and the target process is 64 bit. In that case then I believe the
CreateRemoteProcesstrick simply fails.All in all, I would use
TerminateProcess.