Hibernate computer with a timeout from command line on Windows 7

64

37

I am trying to hibernate my computer from the command. I was using shutdown /s /t 20 to shutdown the the computer. I change /s to /h to hibernate and now it just returns the usage text as if it doesn't recognise what I have entered. In this is does say

/h         Hibernate the local computer.

Is there something else that I need to use with /h to get it to hibernate?

A Jackson

Posted 2009-12-15T09:57:40.443

Reputation: 807

But in this case (the case that you use waitfor or something like that) you can't abort the scheduled hibernation.... – None – 2012-02-03T21:57:23.933

Answers

77

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)

Phoshi

Posted 2009-12-15T09:57:40.443

Reputation: 22 001

6Why we can't set time for hibernate? it wouldn't difficult for windows developers to allow this feature. but why they didn't? O.o – Amirreza Nasiri – 2014-10-17T04:35:29.007

haha, +1 for this nice "sleep" replacement :) i wrote my own .exe to do this, but .. hehahahahr. – akira – 2010-05-26T07:42:03.157

Nice but && not working in powershell – Dr Deo – 2018-10-12T20:06:35.290

Note: the > NUL 2>&1 part will prevent any output from the ping (for more see related question).

– Top-Master – 2019-10-03T04:38:14.690

35

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?

Radko Dinev

Posted 2009-12-15T09:57:40.443

Reputation: 351

1Both options works, but the first is better. If you want to cancel the command via <kbd>Ctrl</kbd>+<kbd>C</kbd>, the first option will be canceled, but the second will receive a false in the first condition and jump to shutdown command directly. – IgniteCoders – 2018-06-14T15:43:15.807

10

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

Craig

Posted 2009-12-15T09:57:40.443

Reputation: 101

i hsve tried the command At 22:30 shutdown /h /fin cmd prompt , i got a message like access denied but i'm the admin in my pc. awaiting for your respose – Smart003 – 2018-05-27T05:11:47.487

I believe in Windows 10 they've changed the permissions required to use 'at'. It's only intended for system jobs and you have to be SYSTEM account in order to execute it. Yes, SYSTEM is more privileged that admin accounts (locally) and yes, there is a way to get a command prompt under the SYSTEM account. – Thanasis Kapelonis – 2018-11-30T03:42:03.660

8

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

Josip Medved

Posted 2009-12-15T09:57:40.443

Reputation: 8 582

3

Of course you can set TIME for hibernation.

If You really want to hibernate your computer after a specific time, all you need to do is to enter this command below into the cmd i.e:

    timeout /t 36000 /nobreak & shutdown /h

Now the computer will start to count down from 36000 to 0 before it will hibernate. But you should note that you can change 36000 into any number of seconds that suits you.

Ace Cube001

Posted 2009-12-15T09:57:40.443

Reputation: 31

3

If you have cygwin it's very simple: sleep 45m && shutdown /h

You can instruct sleep in minutes, hours, seconds and even days. Check out this answer about sleep.

Dominykas Mostauskis

Posted 2009-12-15T09:57:40.443

Reputation: 312

2

I was also searching for timed hibernate for long time. Finally I made the following solution:

Create a bat file as below:

timeout /t %1 /nobreak && shutdown /h

Suppose it is saved in C:\hibernate.bat

Then open Run command (Win+R) and run the bat file with the timeout seconds as below:

C:\hibernate.bat [timeout]

user3702551

Posted 2009-12-15T09:57:40.443

Reputation: 21

The best solution IMHO. It's not hackish (like using ping, or redirecting timeout to NUL), it's practical. – Petr Bodnár – 2020-01-09T18:24:40.520

2

Did you try the Windows Task Scheduler? If you have the script you can set it to run at a certain time - this should answer the time delay question.

Bill

Posted 2009-12-15T09:57:40.443

Reputation: 21

2

i always use this:

shutdown -h

annonymous

Posted 2009-12-15T09:57:40.443

Reputation: 21

@Synetech It wouldn't difficult for windows developers to allow this feature. but why they didn't? O.o – Amirreza Nasiri – 2014-10-17T04:35:52.663

It doesn’t matter, you can’t time a hibernation (for some reason). – Synetech – 2013-12-14T23:38:53.550

-2

Instead of / use -.

Use the below command in the CMD as admin priv and test

shutdown -h

Vamsi Harish

Posted 2009-12-15T09:57:40.443

Reputation: 1