@echo off
title Disable VBS, HVCI, Hyper-V, Device Guard
color 0A

:: ==========================================
:: Requires Administrator
:: ==========================================

net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Run this batch file as Administrator.
    pause
    exit
)

echo.
echo Backing up registry...
reg export "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" "%~dp0DeviceGuard.reg" /y >nul
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" "%~dp0Lsa.reg" /y >nul
reg export "HKLM\SYSTEM\CurrentControlSet\Control\CI" "%~dp0CI.reg" /y >nul

echo.
echo Disabling Device Guard...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" /v EnableVirtualizationBasedSecurity /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" /v RequirePlatformSecurityFeatures /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard" /v Locked /t REG_DWORD /d 0 /f

echo Disabling HVCI...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity" /v Enabled /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity" /v Locked /t REG_DWORD /d 0 /f

echo Disabling Credential Guard...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\CredentialGuard" /v Enabled /t REG_DWORD /d 0 /f

echo Disabling Secure Launch...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\SystemGuard" /v Enabled /t REG_DWORD /d 0 /f

echo Disabling LSA Protection...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /v RunAsPPL /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /v RunAsPPLBoot /t REG_DWORD /d 0 /f

echo Disabling Vulnerable Driver Blocklist...

reg add "HKLM\SYSTEM\CurrentControlSet\Control\CI\Config" /v VulnerableDriverBlocklistEnable /t REG_DWORD /d 0 /f

echo Disabling Hypervisor...

bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off

echo Removing Hyper-V features...

dism /online /disable-feature /featurename:Microsoft-Hyper-V-All /NoRestart
dism /online /disable-feature /featurename:VirtualMachinePlatform /NoRestart
dism /online /disable-feature /featurename:HypervisorPlatform /NoRestart
dism /online /disable-feature /featurename:Containers-DisposableClientVM /NoRestart
dism /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux /NoRestart

echo Disabling Windows Sandbox...
dism /online /disable-feature /featurename:Containers-DisposableClientVM /NoRestart

echo.
echo ======================================
echo Finished.
echo Restart your PC.
echo ======================================
pause