Skip to main content

How to Check if Hyper-V is Enabled in Batch Script

Hyper-V is Microsoft's hardware virtualization technology that allows you to run virtual machines on Windows. For developers, data scientists, and IT professionals, Hyper-V is a critical dependency for tools like Docker, the Windows Subsystem for Android (WSA), and the Windows Sandbox. Before launching a virtualized environment, it is essential to verify that Hyper-V is actually enabled and active. Using a Batch script, you can automatically query the system features or the hypervisor's boot state to ensure your environment is ready. This guide explains how to check for Hyper-V using systeminfo, dism, and sc.

Why Check for Hyper-V?

  • Dependency Check: Preventing a script from failing when it tries to start a Virtual Machine on a system where Hyper-V is off.
  • Hardware Compatibility: Confirming that the system not only has Hyper-V enabled in Windows but also in the BIOS/UEFI.
  • Troubleshooting: Identifying if a "Blue Screen" or performance drop is related to conflicts with the Hyper-V hypervisor.
No Administrative Rights for Simple Checks

While enabling Hyper-V requires administrator rights, checking whether it is currently running can often be done with standard user privileges.

Method 1: Using systeminfo (Human-Readable)

The systeminfo command provides a dedicated section for "Hyper-V Requirements" at the bottom of its output. This is the easiest way to see the current state.

@echo off
echo [PROCESS] Checking Hyper-V requirements and status...
systeminfo | findstr /C:"Hyper-V Requirements"
pause

Understanding the Results:

  • A hypervisor has been detected: This means Hyper-V is currently ENABLED and running.
  • Virtualization Enabled In Firmware: Yes: This means the BIOS supports it, but the Windows feature might still be off.

Method 2: Using DISM (Feature State)

The dism utility checks if the Windows Feature itself is toggled on, regardless of whether the hypervisor is currently active in the kernel.

@echo off
echo [PROCESS] Checking Windows Optional Feature state...

:: Note: Check for the Hyper-V bundle name
dism /online /get-featureinfo /featurename:Microsoft-Hyper-V-All 2>nul | findstr /i /c:"State" | findstr /i /c:"Enabled" >nul

if %errorlevel% equ 0 (
echo [STATUS] Hyper-V Feature is ENABLED in Windows.
) else (
echo [STATUS] Hyper-V Feature is DISABLED or not available.
)
pause

Method 3: Using sc (Service Status)

Another low-level way is to check the status of the Hyper-V Virtual Machine Management service, which must be running for Hyper-V to function.

@echo off
echo [PROCESS] Checking Hyper-V service status...

sc query vmms >nul 2>&1

if %errorlevel% equ 0 (
sc query vmms | findstr /i /c:"RUNNING" >nul
if %errorlevel% equ 0 (
echo [STATUS] Hyper-V Virtual Machine Management service is RUNNING.
) else (
echo [STATUS] Hyper-V service exists but is NOT running.
)
) else (
echo [STATUS] Hyper-V service is not installed.
)
pause

Creating a Pre-flight Dependency Script

A professional script will check for Hyper-V before attempting to launch a virtualized tool.

@echo off
setlocal

echo ============================================================
echo Hyper-V Dependency Checker
echo ============================================================

:: 1. Check if hypervisor is active
systeminfo | findstr /i /c:"A hypervisor has been detected" >nul

if %errorlevel% equ 0 (
echo [SUCCESS] Hyper-V Hypervisor is running.
) else (
echo [ERROR] Hyper-V is NOT active.
echo [HELP] Please enable 'Hyper-V' in Windows Features
echo [HELP] and ensure 'Virtualization Technology' is ON in BIOS.
pause
exit /b 1
)

:: 2. Launch your tool
echo [PROCESS] Starting Docker/VirtualBox/WSA...
:: call launch_docker.bat

echo ============================================================
pause

Common Pitfalls and How to Avoid Them

Conflicts with Third-Party Virtualization

If you have VirtualBox or VMware installed, they might report that Hyper-V is "enabled" even when those tools are struggling to run alongside it.

Wrong Way:

:: Assuming Hyper-V is always the only thing running
if exist "C:\Windows\System32\hvix64.exe" ...

Correct Way: Always use systeminfo or BCDEdit to check the hypervisorlaunchtype. If it is set to Auto, Windows will attempt to start the hypervisor on every boot.

Windows Home Edition

Hyper-V is not officially available on Windows Home Edition. If your script runs on Home, the DISM check will fail with "Feature name not found."

SEO and UX Tip

In your script, check the Windows Edition first (see our guide on edition detection). If Home is detected, advise the user to use "Windows Hypervisor Platform" instead of the full Hyper-V suite.

Best Practices for Hyper-V Management

  1. Check BIOS First: If systeminfo says "Virtualization Enabled In Firmware: No," your Batch script cannot fix this. You must tell the user to enter their BIOS settings (usually by pressing F2 or Del on boot).
  2. Verify Slmgr: Sometimes licensing issues can prevent Hyper-V from starting in specific Enterprise environments.
  3. Use for Lab Orchestration: If you are deploying a dev environment to 50 developers, use this script to warn them if their hardware isn't ready for world-class virtualization.
Nested Virtualization

If you are running Windows inside another virtual machine, you must enable "Nested Virtualization" in the host software (like VMware or Azure) before Hyper-V can be enabled inside the guest OS.

Conclusion

Checking if Hyper-V is enabled via Batch script is a fundamental prerequisite for modern software development and system administration. By utilizing systeminfo and dism to verify both the BIOS settings and the Windows feature status, you can create robust automation that prevents crashes and provides clear guidance to users. This professional level of dependency management ensures that your virtualized workloads run smoothly on a verified hardware and software foundation, maintaining the performance and stability of your advanced computing environment.