@echo off
:: 关闭命令回显
chcp 65001 >nul 2>&1

:admin
:: 自动获取管理员权限，窗口隐藏运行
fltmc >nul 2>&1 || (
    powershell -WindowStyle Hidden -Command "Start-Process '%~f0' -Verb RunAs" >nul 2>&1 & exit
)

:check
:: 初始化内存限制标记
set haslimit=0

:: 检测三项系统内存限制
bcdedit /enum {current} | findstr /i "maxmemory" >nul 2>&1 && set haslimit=1
bcdedit /enum {current} | findstr /i "truncatememory" >nul 2>&1 && set haslimit=1
bcdedit /enum {current} | findstr /i "nolowmem" >nul 2>&1 && set haslimit=1

:: 如果有限制则修复
if %haslimit% equ 1 (
    bcdedit /deletevalue {current} maxmemory >nul 2>&1
    bcdedit /deletevalue {current} truncatememory >nul 2>&1
    bcdedit /deletevalue {current} nolowmem >nul 2>&1
    :: 弹出提示：已修复
    powershell "Add-Type -AssemblyName System.Windows.Forms;[System.Windows.Forms.MessageBox]::Show('内存限制已修复，请重启生效','执行成功',0,64)" >nul 2>&1
) else (
    :: 弹出提示：无需修复
    powershell "Add-Type -AssemblyName System.Windows.Forms;[System.Windows.Forms.MessageBox]::Show('未检测到内存限制，系统正常','无需修复',0,64)" >nul 2>&1
)

exit