-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeepClean.bat
More file actions
118 lines (102 loc) · 4.55 KB
/
DeepClean.bat
File metadata and controls
118 lines (102 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@echo off
setlocal EnableDelayedExpansion
:: Set log file path
set "LOGFILE=%UserProfile%\Desktop\Cleanup_Log.txt"
echo *** Deep Clean Log - %date% %time% *** > "%LOGFILE%"
echo Starting Deep Clean Process... >> "%LOGFILE%"
echo Starting Deep Clean Process...
:: Kill common locking processes (excluding explorer and brave)
echo Killing common apps to release file locks...
echo [INFO] Attempting to kill common file-locking apps... >> "%LOGFILE%"
for %%P in (
winword.exe excel.exe chrome.exe firefox.exe msedge.exe teams.exe discord.exe notepad.exe
) do (
echo [INFO] Checking for process: %%P >> "%LOGFILE%"
taskkill /f /im %%P >> "%LOGFILE%" 2>&1
)
:: Initialize counters
set /a DeletedFiles=0
set /a DeletedFolders=0
:: Timestamp helper
for /f "tokens=1-2 delims=." %%a in ("%time%") do set "TS=%date% %%a:%%b"
:: Clean %temp%
echo [%TS%] Cleaning %%temp%% folder... >> "%LOGFILE%"
echo Cleaning %%temp%% folder...
for /f %%f in ('dir /a:-d /b "%temp%" 2^>nul') do (
del /f /q "%temp%\%%f" >> "%LOGFILE%" 2>&1
if not errorlevel 1 set /a DeletedFiles+=1
)
for /d %%d in ("%temp%\*") do (
rd /s /q "%%d" >> "%LOGFILE%" 2>&1
if not errorlevel 1 set /a DeletedFolders+=1
)
:: Clean C:\Windows\Temp
for /f "tokens=1-2 delims=." %%a in ("%time%") do set "TS=%date% %%a:%%b"
echo [%TS%] Cleaning C:\Windows\Temp... >> "%LOGFILE%"
for /f %%f in ('dir /a:-d /b "C:\Windows\Temp" 2^>nul') do (
del /f /q "C:\Windows\Temp\%%f" >> "%LOGFILE%" 2>&1
if not errorlevel 1 set /a DeletedFiles+=1
)
for /d %%d in ("C:\Windows\Temp\*") do (
rd /s /q "%%d" >> "%LOGFILE%" 2>&1
if not errorlevel 1 set /a DeletedFolders+=1
)
:: Take control of Prefetch and force clean it
for /f "tokens=1-2 delims=." %%a in ("%time%") do set "TS=%date% %%a:%%b"
echo [%TS%] Taking ownership of Prefetch for full cleanup... >> "%LOGFILE%"
takeown /F "C:\Windows\Prefetch" /R /D Y >> "%LOGFILE%" 2>&1
icacls "C:\Windows\Prefetch" /grant administrators:F /T >> "%LOGFILE%" 2>&1
attrib -r -s -h "C:\Windows\Prefetch\*.*" /S /D >> "%LOGFILE%" 2>&1
:: Clean Prefetch
echo [%TS%] Cleaning Prefetch... >> "%LOGFILE%"
del /f /s /q "C:\Windows\Prefetch\*.*" >> "%LOGFILE%" 2>&1
:: Clean SoftwareDistribution\Download
echo [%TS%] Cleaning SoftwareDistribution\Download... >> "%LOGFILE%"
del /f /s /q "C:\Windows\SoftwareDistribution\Download\*.*" >> "%LOGFILE%" 2>&1
:: Delete Windows.old
if exist "C:\Windows.old" (
echo [%TS%] Deleting Windows.old... >> "%LOGFILE%"
takeown /F "C:\Windows.old" /R /D Y >>"%LOGFILE%" 2>&1
icacls "C:\Windows.old" /grant administrators:F /T >>"%LOGFILE%" 2>&1
rmdir /s /q "C:\Windows.old" >>"%LOGFILE%" 2>&1
) else (
echo [%TS%] No Windows.old folder found. >> "%LOGFILE%"
)
:: Launch Disk Cleanup
echo Launching Disk Cleanup...
powershell -Command "Start-Process cleanmgr.exe -Verb runAs -Wait"
echo [%date% %time%] Disk Cleanup closed. >> "%LOGFILE%"
:: Clear File Explorer history
for /f "tokens=1-2 delims=." %%a in ("%time%") do set "TS=%date% %%a:%%b"
echo [%TS%] Clearing File Explorer history... >> "%LOGFILE%"
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths" /f >> "%LOGFILE%" 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU" /f >> "%LOGFILE%" 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU" /f >> "%LOGFILE%" 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU" /f >> "%LOGFILE%" 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs" /f >> "%LOGFILE%" 2>&1
:: Clear Recent Items (Home Favorites / Recents)
echo [%TS%] Clearing Recent Items (Favorites/Recents in Home)... >> "%LOGFILE%"
del /f /q "%AppData%\Microsoft\Windows\Recent\*" >> "%LOGFILE%" 2>&1
del /f /q "%AppData%\Microsoft\Windows\Recent\AutomaticDestinations\*" >> "%LOGFILE%" 2>&1
del /f /q "%AppData%\Microsoft\Windows\Recent\CustomDestinations\*" >> "%LOGFILE%" 2>&1
:: Run SFC
echo [%TS%] Running SFC /scannow... >> "%LOGFILE%"
sfc /scannow >> "%LOGFILE%" 2>&1
echo SFC scan complete. >> "%LOGFILE%"
:: Summary
echo. >> "%LOGFILE%"
echo ----------- SUMMARY ----------- >> "%LOGFILE%"
echo Deleted Files: %DeletedFiles% >> "%LOGFILE%"
echo Deleted Folders: %DeletedFolders% >> "%LOGFILE%"
echo Cleanup complete at %date% %time% >> "%LOGFILE%"
:: Prompt to restart
choice /M "Would you like to restart the PC now?"
if errorlevel 2 (
echo Restart declined. >> "%LOGFILE%"
start notepad "%LOGFILE%"
exit /b
) else (
echo Restarting in 10 seconds... >> "%LOGFILE%"
timeout /t 10
shutdown /r /t 0
)