80

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
  • 30,974
  • 14
  • 75
  • 112
A Jackson
  • 977
  • 2
  • 9
  • 8
  • But in this case (the case that you use waitfor or something like that) you can't abort the scheduled hibernation.... –  Feb 03 '12 at 21:57

12 Answers12

91

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,233
  • 2
  • 61
  • 81
  • 1
    haha, +1 for this nice "sleep" replacement :) i wrote my own .exe to do this, but .. hehahahahr. – akira May 26 '10 at 07:42
  • 8
    Why 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 Oct 17 '14 at 04:35
  • Nice but && not working in powershell – Dr Deo Oct 12 '18 at 20:06
  • 1
    Note: the `> NUL 2>&1` part will prevent any output from the `ping` (for more see [related question](https://stackoverflow.com/a/30814001/8740349)). – Top-Master Oct 03 '19 at 04:38
46

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
  • 461
  • 4
  • 3
  • 2
    Both options works, but **the first is better**. If you want to cancel the command via Ctrl+C, the first option will be canceled, but the second will receive a `false` in the first condition and jump to `shutdown` command directly. – IgniteCoders Jun 14 '18 at 15:43
  • The second example can be made better by using `waitfor NUL /t 20 && shutdown /h` instead. – Richard Sep 17 '20 at 06:46
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,204
  • 14
  • 90
  • 93
Craig
  • 131
  • 1
  • 2
  • i hsve tried the command `At 22:30 shutdown /h /f`in cmd prompt , i got a message like access denied but i'm the admin in my pc. awaiting for your respose – Smart003 May 27 '18 at 05:11
  • 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 Nov 30 '18 at 03:42
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
  • 4
Ace Cube001
  • 101
  • 1
  • 3
9

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

Josip Medved
  • 8,862
  • 1
  • 30
  • 42
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,344
  • 36
  • 42
  • 54
2

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,138
  • 25
  • 36
  • 47
  • Could you explain the need for /f parameter? Just `sleep 30 | shutdown /h` worked fine for me. Also, hibernation needs to be enabled, in order for this command to work. – zigzag Jul 20 '22 at 06:49
  • Update: now it hibernates instantly when using the `|` pipeline operator (PowerShell 7), but works correctly using the `&&` pipeline operator: `sleep 30 && shutdown /h` – zigzag Dec 03 '22 at 00:57
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.

Gaff
  • 18,569
  • 15
  • 57
  • 68
Bill
  • 21
  • 1
2

i always use this:

shutdown -h

annonymous
  • 21
  • 1
0

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
  • 7,984
  • 2
  • 19
  • 32
-2

Instead of / use -.

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

shutdown -h
Kevin Panko
  • 7,346
  • 22
  • 44
  • 53