views:

873

answers:

6

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?

A: 

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
Whoops misread.
Byron Whitlock
Leaving in case it is needed by anyone else :D
Byron Whitlock
Keand64 wants to restart application, not the whole system.
Wacek
Technically, if he puts his app in the Run key or in the startup folder, this will restart his app.
Michael
+2  A: 

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
Thanx, could you elaborate a little more on spawning a new process? (I'm fairly new to windows programming)
Keand64
see here: http://stackoverflow.com/questions/1463040/does-windows-have-its-own-call-other-exe-function-c
sbi
+1  A: 

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
A: 

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
A: 

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.

Mads Elvheim
A: 

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.

Tom Kirby-Green