87

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?

Arjan
  • 31,511
A Jackson
  • 1,037

14 Answers14

95

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
  • 23,483
50

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?

13

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
Indrek
  • 24,874
Craig
  • 131
10

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.

namgold
  • 103
9

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

Josip Medved
  • 8,909
3

If you are using PowerShell or have the Windows terminal as your default command-line interface then this is the only solution that has worked for me:

sleep 30 | shutdown /h /f

Of course you can change 30 to whatever amount of seconds you would like.

Dave M
  • 13,250
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.

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]

bertieb
  • 7,543
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.

Gareth
  • 19,080
Bill
  • 21
2

i always use this:

shutdown -h

1

Here is a VBScript that will prompt for the number of seconds before hibernation:

Dim intSeconds,wshShell
intSeconds = InputBox("Enter number of seconds to wait","Hibernate timer")
Wscript.Sleep intSeconds
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run "shutdown.exe -h -f"
wasif
  • 9,176
0

Instead of making multiple batch files, each with different number of seconds to wait, create and use the hibernate-later.bat file, which asks you when exactly you want to hibernate.

Example

@echo off
setlocal enabledelayedexpansion

echo === :question set "answer=0" set /p answer="Hibernate after how many minutes? " cls

rem Validate. echo %answer%| findstr /r "^[1-9][0-9]*$">nul if %errorlevel% equ 0 ( echo Counting... ) else ( echo Invalid number. goto :question )

set /A timeout=%answer% * 60 timeout /t !timeout! /nobreak

shutdown /h /f pause

Note that closing the Window cancels hibernate (for me at least), which is useful if you reconsider and decide to change the timer.

0

I used the solution proposed by Radko Dinev for some time. However, converting the number of hours and minutes into seconds every time started to bother me. That's why I decided to write the program myself. I would like to leave here a link to such a program that I authored. Maybe it will be useful to someone who will be looking for a similar solution in the future. The program is free, I do not receive any benefits for downloading and using it. You don't have to convert minutes and hours to seconds. It is also possible to turn off the monitor earlier. hibernationdelayer

-2

Instead of / use -.

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

shutdown -h
Kevin Panko
  • 7,466