Jump to content
Tuts 4 You

Prevent the main thread from closing the application?


Recommended Posts

Will blocking ExitProcess() prevent the main thread from shutting down the application when it ends?

I ask because I am working on a dll which is injected into a target application. And I don't want the application to be exited before the dll is finished and ready to exit.

Link to comment

If you are certain the main thread is calling ExitProcess to close/terminate the application, you could hook it and call WaitForSingleObject with your threads handle to force the application to wait for your thread to finish. Then let ExitProcess continue as normal.

Link to comment

I think once the main thread returns to kernel32.dll, t calls ExitProcess, at least on XP...

However, it's not very safe to assume kernel32.dll calls ExitProcess on every Windows version.

TerminateThread on the main thread terminates the process as well, and I doubt it calls ExitProcess internally.

Guess you gotta hook a few more APIs apart from ExitProcess there to be 100%ly sure.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...