tags:

views:

151

answers:

2

I have a C++ exe; under a particular scenario I need to stop the exe and start it up again. This has to be done from within the same exe and not from outside. What is the best way to achieve this?

My guess is to start a new instance of the process and then kill the running process. But is there any straight forward API to do this, like RestartProcess() or something? If not what do you suggest?

+2  A: 

No, there's no such built-in method. You really have to detect the path to the executable (GetCurrentModule(), then GetModuleFileName()), run the new process (CreateProcess()), then exit the current process (ExitProcess()).

sharptooth
+1  A: 

Use the standard exec function. it runs a program and does not return, in effect replacing the current running program with a new one.

Hasturkun