Hibernate computer with a timeout from command line on Windows 7

I don't believe you can set a time for hibernation, unfortunately.

Try:

ping -n 20 127.0.0.1 > NUL 2>&1 && shutdown /h /f

The ping is a hackish way of delaying the action. -n 20 should wait for 20 seconds.

(the double && will allow you to do a Ctrl+C to cancel the operation, but if you use a simple & then pressing Ctrl+C will only break the timer and then continue to shut down)


You could also consider using "timeout" or "waitfor" commands in a similar manner.

timeout /t 20 /NOBREAK > NUL && shutdown /h

or

waitfor NUL /t 20 || shutdown /h

More here: How do I make a batch file wait / sleep for some seconds?


I use the following:

sleep 20 && shutdown /h /f

Or this if I want it off at a certain time:

At 22:30 shutdown /h /f

I think that it complains about time. Just put shutdown /h and it should work.