4

When I start a long-processing job just before going to sleep myself, I often run

shutdown -s -t 3600

so that the computer automatically shutdowns after 3600 seconds.

How to do the same to ask the computer to go to sleep after x seconds?

I tried

shutdown -h -t 60

but 1) it didn't even work and anyway 2) this would make computer go to hibernation, which I don't want (I prefer sleep mode).

Note: this answer doesn't solve the problem because it doesn't allow to specify a time before going to sleep.

2 Answers 2

2

How do I make Windows 7 go to sleep after x seconds?

Use the following batch file, and run as an Adminstrator

@echo off
rem disable hibernate
powercfg -hibernate off
rem wait x seconds, eg 1 hour
timeout 3600 /nobreak
rem sleep
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0

Further Reading

3
  • thanks. even if it's not vital I was looking for a one line command (i like the simplicity of shutdown -s -t). Is there no?
    – Basj
    Sep 25, 2017 at 6:51
  • Also is powercfg -hibernate off permanent (I thought so) or should it be done after every reboot ?
    – Basj
    Sep 25, 2017 at 6:53
  • @Basj I believe it is permanent (until you turn it on again), but it won't do any hard to turn it off if it is already off.
    – DavidPostill
    Sep 25, 2017 at 18:01
8

A one-liner (based of DavidPostill's accepted answer):

timeout /T 3600 & rundll32.exe powrprof.dll,SetSuspendState 0,1,0

To be sure it works, you can try it like this:

timeout /t 10 & notepad

the Notepad should open after 10 seconds.

Important note: If you have git installed on your computer, its bin folder might be in the PATH, and doing timeout in the command line will run C:\Program Files\Git\usr\bin\timeout.exe instead of the default C:\Windows\System32\timeout.exe! In this case you have to include the full path of timeout, in order to use the Windows timeout tool.

3
  • Unfortunately, after 1 hour, it didn't do anything, just went back to the prompt. If I run the command without the timeout, it does put my computer to hibernate.
    – qwertzguy
    Dec 13, 2020 at 20:13
  • @qwertzguy Please try timeout /t 10 & notepad, what happens?
    – Basj
    Dec 13, 2020 at 20:24
  • it works, it opened notepad after 10 sec. Not sure why it didn't work with the 1 hour and sleep command.
    – qwertzguy
    Dec 31, 2020 at 7:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .