How can I reset a Windows process to a previous state?

c, c++, process, winapi, windows

Solution

There is nothing preventing a Windows service from doing it's real work in a separate process, although admittedly it's a little messy. So I would suggest that you have two exectuables: a parent process, implemented as a service, and a child process, which can exit (and be restarted by the parent) whenever you need to reset the application's state.

Problem

I have a large application with a lot of threads and a lot of complex static objects. Currently, when a user logs out, the application is restarted to forcefully reset the application to it's initial state. This process is being changed to a Windows service, so this approach is no longer possible. Likewise, the code is too much of a mess to properly implement a way to reset state when a user logs out. I was thinking there might be an approach with writing the entire process's initial memory to disk, then loading it when a reset is requested, but this has many problems, such as not being able to save the kernel-mode state. I need a way (however dirty) to reset this process to it's initial state, without actually restarting the process. Does winapi provide anything that can accomplish this for me?

Original source