How can I register a program to auto-relaunch if it crashes or is terminated?

Raymond Chen


A customer wanted a program that auto-relaunched itself if it crashes, or even is explicitly terminated by the user. They were wondering if there was a way to register such a program with the system. Right now, they have a second program that monitors the first, and if the first program crashes, then the second program relaunches it.

Well, if the program is a Windows service, then they can configure the recovery policy, either programmatically or via the user interface (on the Recovery tab).

But for regular interactive applications (which is what this program was), there is no such automatic functionality. And since they wanted to make the program auto-restart even if the user explicitly terminates it, I suspect the purpose of the program is not so much to assist their users but to monitor (and possibly harrass) them.

At the end of the day, all you can do is build taller and taller walls, and the hostile users will buy taller and taller ladders. In this case, the user could terminate the second program, thereby taking out the monitor, and thus allowing them to terminate the main program with impunity. Or they could suspend the main program, so that it doesn’t terminate but doesn’t do anything useful either. If you add a heartbeat function, the users could attach a debugger to the program and patch out the code that implements the undesirable behavior and leaves just the heartbeat.

At this point, it’s a matter of how hostile a user you want to defend yourself against.

Raymond Chen
Raymond Chen

Follow Raymond