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?
-
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 :DWacek : Keand64 wants to restart application, not the whole system.Michael : Technically, if he puts his app in the Run key or in the startup folder, this will restart his app. -
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.)
Keand64 : Thanx, could you elaborate a little more on spawning a new process? (I'm fairly new to windows programming)sbi : see here: http://stackoverflow.com/questions/1463040/does-windows-have-its-own-call-other-exe-function-c -
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.
-
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...
-
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.
-
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 comments:
Post a Comment