Hibernating Via Batch File

When you reboot or shut down your computer, you normally have to save all your open documents and close all running programs, because when the computer restarts, your system will restart in “default mode” (no programs or documents open).

Microsoft added support for “hibernation” in Windows 2000 (and refined it further in XP and Vista). Hibernation mode writes the contents of the system RAM to the hard disk, which means that when you “hibernate” a computer, everything you had open – such as a web browser and email program – remain open when you restart your computer. In other words, if you were to type something in a Notepad window and restart your computer without saving the document, the data will be lost forever if you reboot\shutdown, but will remain on your computer if you hibernate.

The only downside to hibernation is that Windows creates a “hibernation file” (HIBERFILE.SYS) on your system that’s equal in size to the amount of RAM that you have. So if you have 2GB of RAM, Windows needs a 2GB HIBERFILE.SYS file on your system.

It can be annoying having that 2GB HIBERFILE.SYS file hanging out all the time if you’ve installed Windows on a smaller hard drive or partition, especially if you’re like me and only hibernate your system when the electricity goes out and you want to shut down your PC before your UPS runs out of juice.

Thankfully, there’s an easy way to create a batch file that will 1) enable hibernation mode and 2) set the computer to hibernate. You’ll need to download PSSHUTDOWN, a tiny (free) utility from the Windows Sysinternals website for this.

1) Download the PsTools collection from the web site above.

2) Unzip the PsTools.zip file and move the PSSHUTDOWN.EXE file to your Windows directory (you can delete the rest of the files from the PSTools kit, but there are some great utilities included with it that you should check out!)

3) Open Notepad, paste the following text into the window, and save the file as a .CMD file:

powercfg /hibernate on
psshutdown -h

The first line enables hibernation, while the second tells the computer to go into shutdown mode. If you wish, you could create a second batch file that has only “powercfg /hibernate off” in it, to disable hibernation with a single click.

Also, if you don’t want to download the PSSHUTDOWN tool, you can force hibernation by changing the second line of the batch file to:

%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Hibernate

Note that the above should all be on one line; also, although this “alternate method” is built-in to Windows, I personally find the first option (psshutdown -h) easier to use.

Lastly, remember that you’ll actually need the space HIBERFILE.SYS will take up when you enable hibernation, so don’t go filling up your system partition! You’d need to quickly delete a bunch of stuff if the power goes out, which kind of defeats the hwole point of using a batch file to quickly enable hibernation!

8 Replies to “Hibernating Via Batch File”

  1. It’s not specific to laptop – it will work with any version of XP. I *don’t* think it will work with Vista, however. I’ll look into that and get back to you.

  2. Thank you very much.

    But “psshutdown -h” and its rundll32 equivalent works partially for me.
    The hibernate action is tiggered and windows XP does hibernate,
    but it resumes within seconds, on its own,
    unless, I monitor the progress of hibernation, and switch off the power before
    (ie win the race)

    Could I be missing any Service Pack.
    (I am running XP Pro, with SP 3 on a desktop, powered by a Intel Core2 Duo QUAD prcessor)

  3. That sounds like either a hardware\driver problem… although I have the same problem in Win7 x64 on my triple-core box. I’ve never bothered to troubleshoot it, as the only time I ever hibernate this computer (or even turn it off) is when there is a storm in the area.

  4. Hey, Thanks a lot. This is just what I was looking for.

    BTW, I used the second option above “%windir%\…SetSuspendState Hibernate” which works fine. I’m embedding this at the end of my nightly backup so I won’t be drawing energy all night.

    J

  5. Thanks for the alternative solution to Hibernating per script.

    Do you know you can also do it with the “Shutdown” command in Windows?
    shutdown /h

    Look at “shutdown /help” for a bunch of neat things you can do with it…

    Have a lot of fun…

  6. When running the batch file, the command line out put has this:
    C::>powercfg -hibernate off
    You do not have permission to enable or disable the Hibernate feature.

    It appears the script has to be run as an administrator……

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.