@echo off :: Check if running as admin if not "%Administrator%" == "true" ( echo This script must be run as an administrator. pause exit ) :: Set log file set log_file=%userprofile%\Desktop\WindowsRepair.log :: Backup existing BCD echo Backing up existing BCD... >> %log_file% bcdedit /export c:\BCD_Backup >> %log_file% 2>&1 :: Repair BCD echo Repairing BCD... >> %log_file% bcdedit /import c:\BCD_Backup >> %log_file% 2>&1 bcdedit /set {default} bootstatuspolicy ignoreallfailures >> %log_file% 2>&1 bcdedit /set {default} recoveryenabled No >> %log_file% 2>&1 :: Find and mount Windows installer for /f "tokens=1,2" %%i in ('wmic logicaldisk where drivetype^=3 get caption^, volumename ^| findstr /i "Windows"') do ( set installer_drive=%%i set installer_name=%%j ) if not defined installer_drive ( echo No Windows installer found. pause exit ) echo Found Windows installer on drive %installer_drive% with name "%installer_name%". :: Repair Wim image using the Windows installer echo Repairing Wim image using the Windows installer... >> %log_file% dism /image:%installer_drive%\ /cleanup-image /revertpendingactions >> %log_file% 2>&1 dism /online /cleanup-image /scanhealth >> %log_file% 2>&1 if %errorlevel% neq 0 ( echo Wim image repair failed with error code %errorlevel%. Check log for details. type %log_file% pause exit ) dism /online /cleanup-image /restorehealth /source:%installer_drive%\install.wim >> %log_file% 2>&1 if %errorlevel% neq 0 ( echo Wim image repair failed with error code %errorlevel%. Check log for details. type %log_file% pause exit ) :: Repair System files using SFC echo Repairing system files using SFC... >> %log_file% sfc /scannow /offbootdir=c:\ /offwindir=c:\windows >> %log_file% 2>&1 if %errorlevel% neq 0 ( echo System file repair failed with error code %errorlevel%. Check log for details. type %log_file% pause exit ) :: Check and repair file system errors using CHKDSK echo Checking and repairing file system errors using CHKDSK... >> %log_file% chkdsk /f /r c: >> %log_file% 2>&1 if %errorlevel% neq 0 ( echo File system error repair failed with error code %errorlevel%. Check log for details. type %log_file% pause exit ) :: Check for and display errors in the log file echo Checking for errors... find /i "error" %log_file% > nul && ( echo The following errors were found: find /i "error" %log_file% pause ) echo Repair process complete. Check log for details. type %log_file% pause