Have fixed the maintenance batch script. Have a play if you like,
Mike
- When double clicking on the batch file, the script now restarts and runs as Administrator
- Alternatively: Right click on the batch file and "Run as Administrator
- Fixed option 9. Run All: Everything runs and completes in order
- (PnPClean + CheckHealth + RestoreHealth + Analyze + Clean + SFC)
- Added message to warn that restorehealth may take a while and appear to freeze at various stages and after 100.0%
1. PnPClean only
This command removes outdated or unnecessary device drivers from your system. It cleans up orphaned drivers (drivers that are no longer in use or associated with any hardware), helping to free up space and potentially improving system performance.
2. CheckHealth only
The `CheckHealth` option scans your system for corruption or issues in the Windows image. It doesn’t fix anything but will tell you whether the system has any integrity violations or corruption that could potentially affect Windows' functionality.
3. RestoreHealth only
The `RestoreHealth` option uses the Windows Update system or local repair sources to automatically fix any corruption or integrity issues found in the Windows image. It can replace corrupted system files with healthy versions, repairing system issues.
Due to the fact restorehealth /online can sometimes look like it has frozen at 100.0%, I have added a message that shows prior to restorehealth running: "Restorehealth may appear to pause at various stages and at 100.0%. Please be patient, it's working and can sometimes take a long time.."
4. RestoreHealth + SFC
This combines the `RestoreHealth` command with `SFC` (System File Checker). First, `RestoreHealth` attempts to repair any corruption in the system image, and then `SFC` scans and repairs any specific corrupted system files that might remain.
5. Analyze Component Store only
This option checks the state of the Component Store, which is the folder where Windows stores files related to updates, system components, and Windows features. It analyzes whether there’s any unnecessary data or issues, like excess update files, which can sometimes slow down your system or take up unnecessary space.
6. Clean Component Store only
This command removes unnecessary or outdated files from the Component Store. This can help reduce the size of the Windows installation and free up disk space. It doesn’t fix corruption but instead cleans up old update files, repair logs, and other unused components.
7. Analyze + Clean Component Store
This combines both `Analyze Component Store` and `Clean Component Store`. It first checks for issues or unnecessary files in the Component Store and then proceeds to clean up old and unused files, reducing clutter and saving space.
8. SFC only
The `SFC` (System File Checker) command scans and repairs individual corrupted or missing system files in Windows. It checks protected system files and replaces them with correct versions from a local cache or from the Windows installation files.
9.Run All
Runs all of the above.
10. Exit
Closes the command window
antspants_post_update_batch-1.8 batch file content:
Batch:
@echo off
title Windows 11 System Maintenance
:: --- Self-elevate to Administrator ---
net session >nul 2>&1
if %errorlevel% neq 0 (
echo Requesting administrative privileges...
powershell -Command "Start-Process '%~f0' -Verb RunAs"
exit /b
)
:MENU
cls
color 0A
echo ==============================
echo Windows 11 Maintenance Menu
echo Version 1.8
echo ==============================
echo %date% %time%
echo ==============================
echo ----------------------------------------------
echo Please select an option from the list below by
echo typing its number and pressing Enter.
echo ----------------------------------------------
echo.
echo 1. PnPClean only
echo 2. CheckHealth only
echo 3. RestoreHealth only
echo 4. RestoreHealth + SFC
echo 5. Analyze Component Store only
echo 6. Clean Component Store only
echo 7. Analyze + Clean Component Store
echo 8. SFC only
echo 9. Run All (PnPClean + CheckHealth + RestoreHealth + Analyze + Clean + SFC)
echo 10. Exit
echo.
set /p choice="Select an option (1-10): "
color 07
:: --- Input validation ---
if "%choice%"=="" goto INVALID
for /f "delims=0123456789" %%A in ("%choice%") do goto INVALID
if %choice% lss 1 goto INVALID
if %choice% gtr 10 goto INVALID
:: --- Menu routing ---
if "%choice%"=="1" goto PNPONLY
if "%choice%"=="2" goto CHECK
if "%choice%"=="3" goto RESTORE
if "%choice%"=="4" goto RESTORESFC
if "%choice%"=="5" goto ANALYZESTORE
if "%choice%"=="6" goto CLEANSTORE
if "%choice%"=="7" goto ANALYZECLEAN
if "%choice%"=="8" goto SFCONLY
if "%choice%"=="9" goto RUNALL
if "%choice%"=="10" exit
:INVALID
echo Invalid choice, please select 1–10.
pause
goto MENU
:PNPONLY
call :PNPCLEAN
pause
goto MENU
:CHECK
call :CHECKHEALTH
pause
goto MENU
:RESTORE
call :RESTOREHEALTH
pause
goto MENU
:RESTORESFC
call :RESTOREHEALTH
call :SFC
echo [INFO] RestoreHealth + SFC finished.
pause
goto MENU
:ANALYZESTORE
call :DO_ANALYZESTORE
pause
goto MENU
:CLEANSTORE
call :DO_CLEANSTORE
pause
goto MENU
:ANALYZECLEAN
call :DO_ANALYZESTORE
call :DO_CLEANSTORE
echo [INFO] Analyze + Clean Component Store finished.
pause
goto MENU
:SFCONLY
call :SFC
pause
goto MENU
:RUNALL
call :PNPCLEAN
call :CHECKHEALTH
call :RESTOREHEALTH
call :DO_ANALYZESTORE
call :DO_CLEANSTORE
call :SFC
echo [INFO] Run All sequence finished.
pause
goto MENU
:PNPCLEAN
echo Running PnPClean...
rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
if errorlevel 1 (
echo [ERROR] PnPClean failed.
) else (
echo [INFO] PnPClean finished.
)
goto :EOF
:CHECKHEALTH
echo Running CheckHealth...
set "tempfile=%TEMP%\checkhealth.txt"
dism /Online /Cleanup-Image /CheckHealth > "%tempfile%" 2>&1
if errorlevel 1 (
echo [ERROR] CheckHealth failed.
) else (
findstr /C:"No component store corruption detected" "%tempfile%" >nul
if not errorlevel 1 (
echo [INFO] No corruption detected.
) else (
echo [INFO] Corruption detected.
)
)
del "%tempfile%" >nul 2>&1
goto :EOF
:RESTOREHEALTH
echo Running RestoreHealth...
echo RestoreHealth may appear to pause at various stages and at 100.0%%. Please be patient, it's working and can sometimes take a long time...
dism /Online /Cleanup-Image /RestoreHealth
if errorlevel 1 (
echo [ERROR] RestoreHealth failed.
) else (
echo [INFO] DISM RestoreHealth finished.
)
goto :EOF
:DO_ANALYZESTORE
echo Running AnalyzeComponentStore...
dism /Online /Cleanup-Image /AnalyzeComponentStore
if errorlevel 1 (
echo [ERROR] AnalyzeComponentStore failed.
) else (
echo [INFO] AnalyzeComponentStore finished.
)
goto :EOF
:DO_CLEANSTORE
echo Running StartComponentCleanup...
dism /Online /Cleanup-Image /StartComponentCleanup
if errorlevel 1 (
echo [ERROR] StartComponentCleanup failed.
) else (
echo [INFO] Component Store cleanup finished.
)
goto :EOF
:SFC
echo Running SFC scan...
sfc /scannow
if errorlevel 1 (
echo [ERROR] SFC scan encountered issues.
) else (
echo [INFO] SFC finished.
)
goto :EOF