Skip to content

Instantly share code, notes, and snippets.

@byigitt
Created September 3, 2024 13:00
Show Gist options
  • Select an option

  • Save byigitt/a51a97e931dc60ce1c2ea72cb612e293 to your computer and use it in GitHub Desktop.

Select an option

Save byigitt/a51a97e931dc60ce1c2ea72cb612e293 to your computer and use it in GitHub Desktop.
a batch script to delete stuff
@echo off
:: Request Admin Permissions
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Now Running As Administrative Privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
pushd "%CD%"
CD /D "%~dp0"
:: Start of parallel cleaning tasks
color 1E
Title Parallel Clear
echo This script will stop the update running service and delete "Update files" in parallel.
echo Are you sure you want to clean and delete files?
pause
:: Parallel execution
start /b cmd /c (
echo Cleaning Windows Temp Folder...
del /s /f /q %windir%\Temp\*.*
rd /s /q %windir%\Temp
md %windir%\Temp
)
start /b cmd /c (
echo Cleaning Local Temp Folder...
del /s /f /q %Temp%\*.*
rd /s /q %Temp%
md %Temp%\
)
start /b cmd /c (
echo Cleaning Windows Prefetch Folder...
del /s /f /q %windir%\Prefetch\*.*
rd /s /q %windir%\Prefetch
md %windir%\Prefetch
)
start /b cmd /c (
echo Cleaning User Local Settings Temp Folder...
del /s /f /q "%USERPROFILE%\Local Settings\Temp\*.*"
rd /s /q "%USERPROFILE%\Local Settings\Temp"
md "%USERPROFILE%\Local Settings\Temp"
)
start /b cmd /c (
echo Cleaning Recent Folder...
del /s /f /q "%APPDATA%\Microsoft\Windows\Recent\*.*"
rd /s /q "%APPDATA%\Microsoft\Windows\Recent"
md "%APPDATA%\Microsoft\Windows\Recent"
)
start /b cmd /c (
echo Cleaning AutomaticDestinations Folder...
del /s /f /q "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations\*.*"
rd /s /q "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations"
md "%APPDATA%\Microsoft\Windows\Recent\AutomaticDestinations"
)
start /b cmd /c (
echo Cleaning CustomDestinations Folder...
del /s /f /q "%APPDATA%\Microsoft\Windows\Recent\CustomDestinations\*.*"
rd /s /q "%APPDATA%\Microsoft\Windows\Recent\CustomDestinations"
md "%APPDATA%\Microsoft\Windows\Recent\CustomDestinations"
)
start /b cmd /c (
echo Deleting Run Command History from Registry...
REG Delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU /VA /F
)
start /b cmd /c (
echo Deleting Typed Paths from File Explorer Registry...
REG Delete HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths /VA /F
)
start /b cmd /c (
echo Deleting Windows .bak files...
del /s /q /f c:\*.bak
)
start /b cmd /c (
echo Cleaning Windows Update Download files...
net stop wuauserv
rmdir %windir%\softwaredistribution /s /q
net start wuauserv
)
start /b cmd /c (
echo Cleaning Recycle Bin...
powershell.exe Clear-RecycleBin -force -ErrorAction:Ignore
)
:: Wait for all parallel tasks to finish
echo Waiting for all tasks to complete...
timeout /t 5 /nobreak >nul 2>&1
echo.
echo.
echo All cleaning tasks completed successfully.
pause
exit /B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment