2

In a windows project I am working on, I intend to have a menu selection that copletely restarts the app. Is there a Windows or C++ function that does this?

6 Answers6

3

There isn't a built-in for this, but a well-designed application can simply stop everything that's going on and then loop back to the start. If you want a true 'fresh start', you will have to spawn a new process (possibly as the last thing you do before the old one shuts down.)

coppro
  • 14,338
  • 5
  • 58
  • 73
  • Thanx, could you elaborate a little more on spawning a new process? (I'm fairly new to windows programming) –  Sep 22 '09 at 22:26
  • 1
    see here: http://stackoverflow.com/questions/1463040/does-windows-have-its-own-call-other-exe-function-c – sbi Sep 22 '09 at 23:24
2

No, you must do it yourself. For instance, you can run external process which will wait until you exit your application, and then run it again.

Wacek
  • 4,326
  • 2
  • 19
  • 28
1

Actually you might want to take a look at the Restart Manager API that came in with Windows Vista. As ever you can p-invoke this to your hearts content and theirs explicit support coming for it in Visual C++ 2010.

0

Already needed to do this. The easiest way without any further reading would be to write a simple .bat-file (either by hand or dynamically by your application) starting your program and then calling that bat-file from your application.

The bat-file may even contain a line to remove itself after having started your app...

Atmocreations
  • 9,923
  • 15
  • 67
  • 102
0

You want to call CreateProcess and then close your current instance of the application gracefully with ExitProcess(), or if you link to the C runtime, just return from main(). But first you should ask yourself why you need to recreate the process in the first place.

-3

ExitWindowsEx is what you want. You can also run the shutdown.exe utility built into windows.

shutdown -t0 -r (restart the system after 0 seconds)
Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168