restart/shutdown Windows

My program is running on its own all day and night. I’d like to restart the computer sometime at night to clear up memory etc. I’ve noticed that trying to shutdown the pc, before exitting the OFW app, it hangs on trying to clear memory for something (possibly quicktime).

One idea might be to quit the software from within ofw at a set time, say 8pm. Then at 8.30 a windows scheduled tasks shuts down the pc.

Do you know any c++ lib that will let you restart/shutdown a pc so I can do it from within my code?


hey chris - I looked at doing this once.
tomorrow I can send you a lib that I made from the microsoft DDK -

it will have a function that you can call to reastart or shut down the computer.

I knew someone would want it :slight_smile:

you can also try this command:

“SHUTDOWN -r -t 01”
so it would be

system ( “shutdown -r -t 01”);

(the forum doesn’t let me type system () function for obvious reasons, so I put spaces in there)

I think there might be postings about calling system elsewhere (and you can take a look at ofUtils launchBrowser…

I’m a bit afraid to try it now, but I think it’ll work. there is also info on that link about powering down the machine, etc if you need.

take care!!


I have looked into this now. The problem with calling shutdown, is that the app crashes upon exit.

If from windows you call:
shutdown -r -t 00

It attempts to restart the computer. It closes the app window, then tries to close the console window, causing it to bring up the quicktime unloading error

So it never restarts, as the error dialogue box keeps it open.

Any ideas? Thanks

can you try force quiting the app from the command line and see if it give an error?…-e-taskkill

then you could run a bat script - first, kill the app, sleep for a second then restart the computer.

we will look at the qt issue, but I think it related to us not getting the atExit call when the app is quit in a certain way - I’m not certain we will have a fix for it, but will definitely try.

take care!!

If you call this:
taskkill /IM openFrameworksApp.exe

Unfortunately it still gets the same problem.

However, if you put /f on the end it forces a quit.

taskkill /IM openFrameworksApp.exe /f

yeah - I was thinking in bat file : force quit, take a breath (ie, pause) then call the restart. should be all you need to get the app down and computer restarted.

  • zach

I just found a solution for my related problem.

My app starts automatically when Windows starts. I also want the app to stop when the computer is shutting down after pressing the power button. The error dialog stopped the computer from shutting down.

I found a key in the Windows registry to force a shutdown and not wait for the error message to be clicked away.

[HKEY_CURRENT_USER\Control Panel\Desktop] AutoEndTasks = 1

You can also set the HungAppTimeout to a smaller value to force kill the app even faster.

!! Don’t forget to reboot computer after changing the setting.

Good luck,