Skip to content

Instantly share code, notes, and snippets.

@naxIO
Created July 20, 2024 09:37
Show Gist options
  • Save naxIO/4fe28fe97f0d51a038632029ea69c835 to your computer and use it in GitHub Desktop.
Save naxIO/4fe28fe97f0d51a038632029ea69c835 to your computer and use it in GitHub Desktop.
This Windows 11 script checks and repairs system files without causing data loss. It performs a system file check, disk check, file system repair, Windows image repair, and initiates a Windows update. The system will restart after the script completes. Ensure all open files are saved before running the script.
@echo off
:: BatchGotAdmin
:CheckPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotAdmin ) else ( goto getAdmin )
:getAdmin
echo This script requires administrator privileges. Please confirm the UAC prompt.
powershell -Command "Start-Process '%~f0' -Verb runAs"
exit /b
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
echo This script will check and repair system files. no data will be lost.
echo If everything is fine, no changes will be made.
echo Please save all your open files and documents before proceeding.
echo The system will restart after the script completes.
pause
echo Starting system file check...
sfc /scannow
if %errorlevel% neq 0 (
echo System file check failed with error code: %errorlevel%
exit /b %errorlevel%
)
echo System file check completed.
echo Starting disk check...
chkdsk C: /f /r
if %errorlevel% neq 0 (
echo Disk check failed with error code: %errorlevel%
exit /b %errorlevel%
)
echo Disk check completed.
echo Checking file system repair...
fsutil repair query C:
if %errorlevel% neq 0 (
echo File system repair check failed with error code: %errorlevel%
exit /b %errorlevel%
)
echo File system repair check completed.
echo Starting Windows image repair...
dism /online /cleanup-image /restorehealth
if %errorlevel% neq 0 (
echo Windows image repair failed with error code: %errorlevel%
exit /b %errorlevel%
)
echo Windows image repair completed.
echo Starting Windows update...
wuauclt /updatenow
if %errorlevel% neq 0 (
echo Windows update failed with error code: %errorlevel%
exit /b %errorlevel%
)
echo Windows update completed.
echo System check and repair completed! The system will now restart.
pause
shutdown /r /t 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment