So how are you detecting the user log-off event? Does your program have a message pump? What is your WaitForSingleObject() function using as a handle?