Skip to content

How to Enable or Disable Hibernation in Batch Script

Learn how to toggle hibernation in Windows using Batch Script with powercfg /h, manage the hiberfil.sys file size, and understand its impact on Fast Startup and disk space.

Hibernation allows a computer to save its entire memory state to disk and power off completely, resuming exactly where the user left off when powered back on. While convenient for laptop users, the hibernation file (hiberfil.sys) consumes a significant chunk of disk space, often 4–16 GB or more depending on installed RAM. On systems with limited storage, like budget SSDs, disabling hibernation is one of the quickest ways to reclaim valuable space.

In this guide, we will explore how to enable and disable hibernation using Batch Script, manage the hibernation file size, and handle the relationship between hibernation and Fast Startup.

The Simple Commands

Windows provides the powercfg utility with built-in switches for toggling hibernation. These are the most straightforward commands available.

Disabling Hibernation

@echo off
setlocal

:: Verify Admin Rights
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Administrator privileges required.
    pause
    exit /b 1
)

echo Disabling Hibernation...

powercfg /h off

if %errorlevel% equ 0 (
    echo [SUCCESS] Hibernation has been disabled.
    echo The hiberfil.sys file has been deleted.
    echo Disk space has been reclaimed.
    echo.
    echo [NOTE] Fast Startup has also been disabled as a side effect.
) else (
    echo [ERROR] Failed to disable hibernation.
)

pause

Enabling Hibernation

@echo off
setlocal

:: Verify Admin Rights
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Administrator privileges required.
    pause
    exit /b 1
)

echo Enabling Hibernation...

powercfg /h on

if %errorlevel% equ 0 (
    echo [SUCCESS] Hibernation has been enabled.
    echo hiberfil.sys has been created on the system drive.
) else (
    echo [ERROR] Failed to enable hibernation.
    echo Your hardware or drivers may not support this feature.
    echo Run "powercfg /a" to check available sleep states.
)

pause

What Happens Behind the Scenes

  • powercfg /h off: Disables hibernation, deletes hiberfil.sys from the system drive, frees disk space, and also disables Fast Startup (which depends on hibernation infrastructure).
  • powercfg /h on: Enables hibernation, creates hiberfil.sys at its default size (typically 40% of installed RAM for the "reduced" type, or 75% for "full" type), and re-enables Fast Startup capability.

Managing the Hibernation File Size

Windows supports two types of hibernation files:

Type Size Supports Full Hibernate Supports Fast Startup
full ~75% of RAM Yes Yes
reduced ~40% of RAM No Yes

If you only need Fast Startup and do not need the "Hibernate" option in the Start Menu, you can shrink the file to the "reduced" size.

Setting a Reduced Hibernation File

@echo off
setlocal

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

echo Setting hibernation file to reduced size (Fast Startup only)...

:: Enable hibernation first (in case it was off)
powercfg /h on >nul 2>&1

:: Switch to reduced type
powercfg /h /type reduced

if %errorlevel% equ 0 (
    echo [SUCCESS] hiberfil.sys is now minimal size.
    echo Fast Startup works, but full Hibernate is unavailable.
) else (
    echo [ERROR] Failed to set reduced hibernation type.
    echo         The system may not support this configuration.
)

pause

Setting a Full Hibernation File

@echo off
setlocal

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

echo Setting hibernation file to full size...

powercfg /h on >nul 2>&1
powercfg /h /type full

if %errorlevel% equ 0 (
    echo [SUCCESS] hiberfil.sys is at full size.
    echo Both Hibernate and Fast Startup are available.
) else (
    echo [ERROR] Failed to set full hibernation type.
)

pause

Setting a Custom Size

You can also set a custom percentage of RAM for the hibernation file using /size.

@echo off
setlocal

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Admin required.
    pause
    exit /b 1
)

:: Set hibernation file to 50% of installed RAM
powercfg /h /size 50

if %errorlevel% equ 0 (
    echo [OK] Hibernation file set to 50%% of RAM.
) else (
    echo [ERROR] Failed to set hibernation file size.
    echo         The minimum allowed value is 40%%. The maximum is 100%%.
)

pause

Checking Current Hibernation Status

Before making changes, you should verify the current state. This script checks both the registry setting and the actual hibernation file.

@echo off
setlocal enabledelayedexpansion

echo =============================================
echo       HIBERNATION STATUS
echo =============================================
echo.

:: Check registry setting
set "status=UNKNOWN"
for /f "tokens=2*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v HibernateEnabled 2^>nul ^| findstr /i "REG_DWORD"') do (
    if "%%B"=="0x1" (set "status=ENABLED") else if "%%B"=="0x0" (set "status=DISABLED") else (set "status=UNKNOWN (%%B^)")
)
echo Registry Status: !status!

:: Check file existence and size
if exist "%SystemDrive%\hiberfil.sys" (
    for /f "tokens=3" %%S in ('dir "%SystemDrive%\hiberfil.sys" /a:hs 2^>nul ^| findstr /i "hiberfil.sys"') do (
        echo hiberfil.sys:    Present on %SystemDrive% (%%S bytes^)
    )
) else (
    echo hiberfil.sys:    Not present on %SystemDrive%
)

:: Check available sleep states
echo.
echo Available Sleep States:
powercfg /availablesleepstates 2>nul | findstr /i "Hibernate Fast"

echo.
pause

Interactive Toggle Script

For IT technicians who need a quick tool to manage hibernation during troubleshooting:

@echo off
title Hibernation Manager
setlocal enabledelayedexpansion

:: Admin check
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Run as Administrator.
    pause
    exit /b 1
)

:menu
cls
echo =============================================
echo       HIBERNATION MANAGER
echo =============================================
echo.

:: Check current status via registry
set "status=UNKNOWN"
for /f "tokens=2*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v HibernateEnabled 2^>nul ^| findstr /i "REG_DWORD"') do (
    if "%%B"=="0x1" (set "status=ENABLED") else if "%%B"=="0x0" (set "status=DISABLED")
)

:: Check file existence
if exist "%SystemDrive%\hiberfil.sys" (
    set "file_info=Present on %SystemDrive%"
) else (
    set "file_info=Not present"
)

echo Current Status:  !status!
echo hiberfil.sys:    !file_info!
echo.
echo [1] Enable Hibernation (Full^)
echo [2] Enable Hibernation (Reduced - Fast Startup only^)
echo [3] Disable Hibernation (Delete hiberfil.sys^)
echo [4] Exit
echo.

set "opt="
set /p "opt=Select: "

if "!opt!"=="1" (
    powercfg /h on >nul 2>&1
    powercfg /h /type full
    echo.
    echo [OK] Full hibernation enabled.
    pause
    goto :menu
)
if "!opt!"=="2" (
    powercfg /h on >nul 2>&1
    powercfg /h /type reduced
    echo.
    echo [OK] Reduced hibernation enabled (Fast Startup only^).
    pause
    goto :menu
)
if "!opt!"=="3" (
    powercfg /h off
    echo.
    echo [OK] Hibernation disabled. Disk space reclaimed.
    echo     Fast Startup has also been disabled.
    pause
    goto :menu
)
if "!opt!"=="4" exit /b 0

echo.
echo Invalid selection.
pause
goto :menu

The Relationship with Fast Startup

Fast Startup (Hybrid Boot) uses the hibernation file to save the kernel session during shutdown. This dependency means:

  • If you disable hibernation (powercfg /h off): Fast Startup is also disabled. Boot times may increase.
  • If you enable hibernation with reduced type: Fast Startup works, but the "Hibernate" option does not appear in the Start Menu power options.
  • If you enable hibernation with full type: Both Fast Startup and full Hibernate are available.

If your only goal is to reclaim disk space without losing Fast Startup, use the reduced type rather than disabling hibernation entirely.

Common Mistakes

The Wrong Way: Manually Deleting hiberfil.sys

:: WRONG - The file is locked by the OS and cannot be deleted directly
del C:\hiberfil.sys /f

The Wrong Way: Expecting Hibernate Without Enabling It

:: WRONG - Assumes hibernation is enabled
shutdown /h

If hibernation was previously disabled via powercfg /h off, the shutdown /h command will fail with "Hibernation is not enabled on this system". Always verify the hibernation state before attempting to hibernate.

The Wrong Way: Setting Custom Size Without Enabling Hibernation First

:: WRONG - /size requires hibernation to already be enabled
powercfg /h off
powercfg /h /size 50

Best Practices

  1. Use powercfg /h off and powercfg /h on: These are the official, supported commands. Never try to manually manipulate hiberfil.sys.
  2. Choose the right type: Use reduced to save disk space while keeping Fast Startup. Use full only if you actually hibernate your machine.
  3. Always check Admin rights: powercfg /h requires elevation. Fail fast with a clear error rather than letting the command produce cryptic failures.
  4. Document the impact: When disabling hibernation in deployment scripts, log that Fast Startup was also disabled as a side effect, and display a message to the user.
  5. Enable before resizing: Always run powercfg /h on before powercfg /h /type or powercfg /h /size to ensure the hibernation infrastructure exists.
  6. Use %SystemDrive% instead of hardcoded C:\: The system drive is not always C:. Use the environment variable to ensure the script works on non-standard installations.
  7. Use powercfg /availablesleepstates: Before enabling hibernation, check whether the hardware supports it. This command lists all available and unavailable sleep states with reasons.

Conclusion

Enabling or disabling hibernation in Batch Script is a single powercfg /h on or powercfg /h off command, but the implications extend to Fast Startup functionality and disk space utilization. By understanding the relationship between the hibernation file types (full vs. reduced), administrators can make precise decisions about the tradeoff between boot speed, power-saving capability, and storage efficiency. Wrapping these commands in an interactive management script provides IT teams with a clean, reusable tool for rapid system configuration.

Navigation