I have a console application and on logoff/shutdown , it exits immediately. I wanted to do some cleanup before the exit, but it doesn't allow me. These are the methods i tried: atexit SetConsoleCtrlHandler SetUnhandledExceptionFilter signal creating a thread which creates an invisible window and has a wndproc All this didn't work. This problem is also reported at http://www.gamedev.net/community/f