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.

Revisions

  1. naxIO created this gist Jul 20, 2024.
    65 changes: 65 additions & 0 deletions systemfix.bat
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    @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