How do I make a hibernation batch file?

25k views Asked by At

I'm trying to make a batch file that executes a simple command:

shutdown -h

I've created a shutdown.bat file with that exact line in it, yet when I run it, all it does is spam the command prompt like crazy.

I've looked at batch file sites, @echo off seems popular, but doesn't that just hide output while the commands are executed just the same?

4

There are 4 answers

0
ryanscottmurphy On BEST ANSWER

It turns out that adding a change directory command to the root of the drive fixes the problem. The final text that I ended up using in the .bat file was:

cd c:\
shutdown /h
8
Teun Pronk On

Would love to say I figured this out but I simply googled it. The code you need is

%windir%System32rundll32.exe powrprof.dll,SetSuspendState

If you go to start -> run and then type this in it should work. So if you have hibernate enabled in the poweroptions this should also work in a batch file.

Hope this helped you

Edit: P.s. click the white little V under the arrows (left of this answer) to accept the answer ;)

1
LJ Neveral On

I believe I am very late for this but just in case someone else comes across this. The issue was indeed with the name of the bat file. You were calling shutdown -h and the bat file was called shutdown.bat hence the bat file was calling itself causing the loop of the command prompts. To fix this you either rename the bat file or specify the directory where shutdown is located.

0
Rashid Qazizada On

For shutdown:

c:\windows\system32\shutdown -s -f -t 00

(or do ...shutdown -p -f).

E.g.: set the time -t 1000 and save and run it.

To abort just c:\windows\system32\shutdown -a in different batch file.

Very important point to note: if you locate this batch file in your startup then it will execute the s/h/r immediately. E.g. you create a logoff batch file and you locate it in startup it will logoff the pc within the given time/immediately. However, when you hold shift when logging then it will abort the logoff batch file otherwise you pc will logoff again and again. You don't have to do this I am not sure if it works on every PC.

Create a user and try it there in case you could not log in. good luck

For restart:

c:\windows\system32\shutdown -r -t 00

For hibernate:

c:\windows\system32\shutdown /h

Reference: https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/