How to Check if Hibernation is Enabled in Batch Script
Hibernation is a power-saving state that saves the entire contents of RAM to a file on disk (hiberfil.sys) before shutting down. When the machine powers back on, it reads this file and restores the exact state the user left off in, including open programs and documents. Understanding whether hibernation is enabled is important for disk space management (the hiberfil.sys file can consume several gigabytes), Fast Startup troubleshooting, and power policy audits.
In this guide, we will explore multiple methods to determine whether hibernation is currently enabled on a Windows machine using Batch Script.
Method 1: Using POWERCFG /A (The Official Check)
The most reliable way to check if hibernation is available and enabled is the powercfg /a command. This command lists all available sleep states on the machine, including Standby (S1/S2/S3), Hibernate, Hybrid Sleep, and Fast Startup.
@echo off
setlocal
echo Checking Hibernation Status...
echo.
:: Run powercfg /a and search for Hibernate in the available section
:: We look for "Hibernate" but exclude lines containing "not available"
powercfg /a | findstr /i "Hibernate" | findstr /v /i "not available" >nul 2>&1
if %errorlevel% == 0 (
echo [RESULT] Hibernation is AVAILABLE on this system.
echo.
echo Detailed sleep state information:
powercfg /a
) else (
echo [RESULT] Hibernation is NOT available or has been disabled.
echo.
echo [INFO] Possible reasons:
echo - Hibernation was disabled via "powercfg /h off"
echo - The hardware/firmware does not support it
echo - A hypervisor is blocking it (Virtual Machine^)
)
pause
Interpreting the Output
The output of powercfg /a will list available and unavailable states. For example:
The following sleep states are available on this system:
Standby (S3)
Hibernate
Fast Startup
The following sleep states are not available on this system:
Standby (S1)
Standby (S2)
If "Hibernate" appears under the available section, hibernation is enabled. If it appears under the not available section (or doesn't appear at all), it is disabled or unsupported.
Method 2: Checking for the hiberfil.sys File
When hibernation is enabled, Windows creates a file named hiberfil.sys at the root of the system drive (C:\). This file is hidden, system-protected, and its size typically equals 40-75% of installed RAM.
@echo off
setlocal
echo Checking for hiberfil.sys...
:: The file is hidden and system-protected, so we need /a:hs
dir C:\hiberfil.sys /a:hs >nul 2>&1
if %errorlevel% == 0 (
echo [RESULT] hiberfil.sys EXISTS.
echo Hibernation infrastructure is in place.
:: Get the file size
for /f "usebackq tokens=3" %%A in (`dir C:\hiberfil.sys /a:hs ^| findstr /i "hiberfil"`) do (
echo File Size: %%A bytes
)
) else (
echo [RESULT] hiberfil.sys NOT FOUND.
echo Hibernation is disabled or was never configured.
)
pause
The Difference Between "Enabled" and "Available"
- If
hiberfil.sysexists ANDpowercfg /alists Hibernate as available, hibernation is fully operational. - If
hiberfil.sysexists but is marked as "reduced" size (viapowercfg /h /type reduced), it means Windows only maintains the file for Fast Startup but not full hibernation. - If
hiberfil.sysdoes not exist, both hibernation and Fast Startup are completely disabled.
Method 3: Registry-Based Check
The hibernation configuration is also reflected in the registry. The key HibernateEnabled explicitly tracks whether the feature is turned on.
@echo off
setlocal
echo Checking Hibernation via Registry...
set "reg_key=HKLM\SYSTEM\CurrentControlSet\Control\Power"
for /f "tokens=3" %%A in ('reg query "%reg_key%" /v HibernateEnabled 2^>nul ^| findstr /i "HibernateEnabled"') do (
set "hib_val=%%A"
)
if not defined hib_val (
echo [WARNING] HibernateEnabled key not found.
echo Hibernation may be unsupported on this hardware.
) else if "%hib_val%" == "0x1" (
echo [RESULT] Hibernation is ENABLED (Registry: HibernateEnabled = 1^)
) else (
echo [RESULT] Hibernation is DISABLED (Registry: HibernateEnabled = 0^)
)
pause
Method 4: Comprehensive Status Report
For audit scripts or system health checks, combining all three methods gives the most complete picture.
@echo off
setlocal enabledelayedexpansion
echo =============================================
echo HIBERNATION STATUS REPORT
echo =============================================
echo.
:: 1. Registry Check
set "reg_status=UNKNOWN"
for /f "tokens=3" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v HibernateEnabled 2^>nul ^| findstr /i "HibernateEnabled"') do (
if "%%A" == "0x1" (set "reg_status=ENABLED") else (set "reg_status=DISABLED")
)
echo Registry (HibernateEnabled^): !reg_status!
:: 2. File Check
set "file_status=NOT FOUND"
dir C:\hiberfil.sys /a:hs >nul 2>&1
if !errorlevel! == 0 set "file_status=PRESENT"
echo Hibernation File (hiberfil.sys^): !file_status!
:: 3. Powercfg Check
set "pcfg_status=NOT AVAILABLE"
powercfg /a 2>nul | findstr /i "Hibernate" | findstr /v /i "not available" >nul 2>&1
if !errorlevel! == 0 set "pcfg_status=AVAILABLE"
echo PowerCfg Sleep States: !pcfg_status!
:: 4. Fast Startup Check (related)
set "fs_status=UNKNOWN"
for /f "tokens=3" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled 2^>nul ^| findstr /i "HiberbootEnabled"') do (
if "%%A" == "0x1" (set "fs_status=ENABLED") else (set "fs_status=DISABLED")
)
echo Fast Startup (HiberbootEnabled^): !fs_status!
echo.
echo =============================================
:: Summary
if "!reg_status!" == "ENABLED" if "!file_status!" == "PRESENT" (
echo SUMMARY: Hibernation is fully operational.
) else if "!reg_status!" == "DISABLED" (
echo SUMMARY: Hibernation has been explicitly disabled.
) else (
echo SUMMARY: Hibernation state is inconsistent. Manual review recommended.
)
pause
Common Mistakes
The Wrong Way: Only Checking the Registry
:: INCOMPLETE - The registry may say enabled, but hardware might not support it
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v HibernateEnabled
Output Concern:
On virtual machines or certain tablet hardware, the registry value might read 0x1 (enabled), but powercfg /a will report "Hibernate - The firmware does not support hibernation." Always cross-reference the registry with powercfg /a for a true status.
The Wrong Way: Using if exist Without Attributes
:: WRONG - hiberfil.sys is a hidden system file, standard if exist may fail
if exist "C:\hiberfil.sys" echo Hibernate is on
Output Concern:
On some Windows configurations, if exist may not detect hidden system files. Using dir /a:hs is more reliable for accessing protected system files.
Best Practices
- Use
powercfg /aas the primary check: It queries the actual firmware capabilities and provides the definitive answer. - Supplement with the registry: The
HibernateEnabledDWORD confirms the administrative intent (whether an admin purposely disabled or enabled it). - Check
hiberfil.sysfor disk audits: When managing disk space, checking the physical existence and size ofhiberfil.systells you exactly how many gigabytes are being consumed. - Combine all methods for audit reports: A comprehensive report that cross-references all three data points provides a full, auditable picture of the hibernation state.
Conclusion
Checking whether hibernation is enabled in Batch Script requires examining the system from multiple angles. The powercfg /a command provides the authoritative firmware-level answer, the HibernateEnabled registry DWORD confirms the administrative configuration, and the physical existence of hiberfil.sys validates that the infrastructure is in place. By combining these three checks, administrators can build robust audit and diagnostic scripts that leave no ambiguity about the system's hibernation capability.