Last active
December 28, 2015 09:33
-
-
Save andras-tim/500320d47dead2e18903 to your computer and use it in GitHub Desktop.
Windows cleaner for multi-user environment - tiny new version of https://github.com/andras-tim/tiaCleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Windows cleaner for multi-user environment | |
:: @author: Andras Tim <[email protected]> | |
:: @source: https://gist.github.com/andras-tim/500320d47dead2e18903 | |
:: | |
:: For no change: set NO_CHANGE=1 | |
:: | |
goto main | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:: Helper functions | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:run | |
:: %* command & arguments | |
if "%NO_CHANGE%" == "1" ( | |
echo ^> %* >&2 | |
) else ( | |
%* | |
) | |
goto :eof | |
:dir | |
:: %1 dir args, %2 path, %3 callback | |
if not exist %2 goto :eof | |
for /f "tokens=*" %%x in ('dir %~1 %2 2^>nul') do ( | |
call %~3 "%~f2\%%x" | |
) | |
goto :eof | |
:find | |
:: %1 dir args, %2 path, %3 pattern, %4 callback | |
if not exist %2 goto :eof | |
echo Finding... %~2\%~3 | |
for /f "tokens=*" %%x in ('dir /s %~1 "%~2\%~3" 2^>nul') do ( | |
call %~4 "%%x" | |
) | |
goto :eof | |
:list_subdirs | |
:: %1 path, %2 callback | |
call :dir "/b /a:d" %1 %2 | |
goto :eof | |
:list_files | |
:: %1 path, %2 callback | |
call :dir "/b /a:-d" %1 %2 | |
goto :eof | |
:find_files | |
:: %1 path, %2 pattern, %3 callback | |
call :find "/b /a:-d" %1 %2 %3 | |
goto :eof | |
:cleanup_dir | |
:: %1 path | |
call :list_subdirs %1 :remove_dir | |
call :list_files %1 :remove_file | |
goto :eof | |
:remove_dir | |
:: %1 path | |
if not exist %1 goto :eof | |
echo Removing directory... %~1 | |
call :run rmdir /s /q %1 | |
goto :eof | |
:remove_file | |
:: %1 path | |
if not exist %1 goto :eof | |
echo Removing file... %~1 | |
call :run del /f /s /a /q %1 >nul | |
goto :eof | |
:delete_journal | |
:: %1 drive | |
call :run fsutil usn deletejournal /d %~1 | |
goto :eof | |
:start_service | |
:: %1 service | |
call :run net start %1 | |
goto :eof | |
:stop_service | |
:: %1 service | |
call :run net stop %1 | |
goto :eof | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:: Cleaner functions | |
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:cleanup_users | |
call :list_subdirs "%USERPROFILE%\.." :cleanup_user | |
goto :eof | |
:cleanup_system | |
:: setup | |
call :stop_service wuauserv | |
call :stop_service TrustedInstaller | |
:: cleanup | |
call :delete_journal %SYSTEMDRIVE% | |
call :cleanup_dir "%SYSTEMDRIVE%\Temp" | |
call :cleanup_dir "%WINDIR%\Temp" | |
call :cleanup_dir "%WINDIR%\Logs\CBS" | |
call :remove_file "%WINDIR%\*.log" | |
call :cleanup_dir "%WINDIR%\SoftwareDistribution\Download" | |
call :cleanup_dir "%WINDIR%\Minidump" | |
call :find_files %SYSTEMDRIVE% *.mdmp :remove_file | |
:: teardown | |
call :start_service TrustedInstaller | |
call :start_service wuauserv | |
goto :eof | |
:cleanup_user | |
call :cleanup_dir "%~1\Local Settings\Temp" | |
call :list_subdirs "%~1\Local Settings\Temporary Internet Files\Content.IE5" :remove_dir | |
call :remove_dir "%~1\Local Settings\Application Data\Google\Chrome\User Data\Default\Cache" | |
call :remove_dir "%~1\Local Settings\Temporary Internet Files\Content.MSO" | |
call :remove_dir "%~1\Local Settings\Temporary Internet Files\Content.Word" | |
call :remove_dir "%~1\Local Settings\Temporary Internet Files\Content.Excel" | |
call :remove_dir "%~1\Local Settings\Temporary Internet Files\OLK???" | |
call :remove_file "%~1\Local Settings\Application Data\VMware\vpx\*.log" | |
goto :eof | |
:main | |
call :cleanup_system | |
call :cleanup_users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment