@echo off
:: Batch script to run SFC /verifyonly, then run SFC /scannow if violations are found
:: Must be run as Administrator

:: Check for admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Please run this script as Administrator.
    pause
    exit /b 1
)

echo ==================================================
echo Running System File Checker in VERIFY mode...
echo ==================================================
sfc /verifyonly > "%temp%\sfc_verify.log"

:: Search for the phrase indicating integrity violations
findstr /C:"Windows Resource Protection found integrity violations" "%temp%\sfc_verify.log" >nul
if %errorlevel% equ 0 (
    echo.
    echo [INFO] Integrity violations detected.
    echo Running SFC /scannow to repair issues...
    echo ==================================================
    sfc /scannow
) else (
    echo.
    echo [INFO] No integrity violations found. No repair needed.
)

:: Cleanup
del "%temp%\sfc_verify.log" >nul 2>&1

echo.
echo [DONE] Script finished.
pause