Time To… Hibernate

I have found now that on a number of occasions that I cannot power my machine off when I wanted to as it is still running a script or something, but I also don’t just want to leave it on just because I cannot sit and wait for it to finish. 

Ever experience something similar?  I also didn’t want to just download another application just to hibernate my machine on a schedule so I decided to look if there was a more “old-school” command line method that I could use that may be able to do it for me…

After some searching I found a post over at howto-connect.com that used the command TIMEOUT at the command line. It uses the number of seconds to wait until the command is run.

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

So running the above command and replacing the xx with 60 (for 1 minute) or 1500 (for 25 minutes) will let the computer “wait” for that period of time before running the command to the RIGHT of the && – so in the above example: shutdown /h

Now all that is good and well, but having to try and work out how many seconds 48 minutes is requires a calculator for me. So I got to thinking… what if I could create a batchfile that would prompt me how many minutes I wanted to wait for, then automatically multiplied it by 60 and then put that result in as the value in the timeout section of the command…

Step #1 would have to be to set a variable called minutes. This would be for the user to type in how many minutes to wait for.

set /p minutes=Enter Minutes To Wait: 

OK now to take that %minutes% variable and multiply it by 60 (seconds).  After looking around I found an interesting article by Rob van der Woude about doing calculations at the command line. In this case a new variable would be created called Result, this from taking the %minutes% and multiplying it by 60. The command I was looking for was:

set /a Result = %minutes% * 60

And then finally to use the %Result% variable in the timeout command:

timeout /t %Result% /NOBREAK > NUL && shutdown /h

So finally we had all the bits of the code, time now to create a batchfile and bring it all together. I decided to name the file HIBERNATE.CMD Here is the contents of the batchfile:

@echo off
set /p minutes=Enter Minutes To Wait: 
echo.
echo Counting down the time...  Please Wait...
set /a Result = %minutes% * 60
timeout /t %Result% /NOBREAK > NUL && shutdown /h

I am pleased to say that although not a pretty GUI or any fancy bells or whistles, it works like a charm for me! Till next time…

MadMike posted at 2020-9-17 Category: Windows / WHS

Leave a Reply

(Ctrl + Enter)