Created
December 11, 2014 22:00
-
-
Save Indemnity83/d254f0e77fd3d09dd7ec to your computer and use it in GitHub Desktop.
Windows Cleanup Script - Quickly free disk space on Windows desktops, servers and terminal servers
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 | |
REM Windx - Windows Cleanup Script | |
REM | |
REM This script is designed to, without mercy or user interaction, clear out | |
REM and clean up temporary files, application caches and known garbage to help | |
REM free up disk space and remove junk. Its usefull to run promptly before a | |
REM virus scan, or defragmentation to help speed up those processes. | |
REM | |
REM This program is free software: you can redistribute it and/or modify | |
REM it under the terms of the GNU General Public License as published by | |
REM the Free Software Foundation, either version 3 of the License, or | |
REM (at your option) any later version. | |
REM | |
REM This program is distributed in the hope that it will be useful, | |
REM but WITHOUT ANY WARRANTY; without even the implied warranty of | |
REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
REM GNU General Public License for more details. | |
REM | |
REM You should have received a copy of the GNU General Public License | |
REM along with this program. If not, see <http://www.gnu.org/licenses/>. | |
REM | |
REM @author Kyle Klaus | |
REM @copyright 2010 Kyle Klaus | |
REM @lastupdate $Date: 2010-06-21 03:48:16 -0700 (Mon, 21 Jun 2010) $ | |
REM @version $Revision: 22 $ | |
REM @link $HeadURL: http://indemnity83.com/svn/scripts/windex/windex.bat $ | |
REM @id $Id: windex.bat 28 2010-07-01 17:15:43Z kklaus $ | |
REM @since April 27th, 2010 | |
REM Global Variables | |
set version=$Revision: 22 $ | |
:: find total free space | |
for /f "tokens=3 delims= " %%A in ('dir /-c %1 ^|find "Dir(s)"') do ( | |
set sfreespace=%%A | |
) | |
Echo ------------------------------------------------------------------------------- | |
Echo WINDEX :: Robust Cleanup Script for Windows :: %version:~1,-1% | |
Echo ------------------------------------------------------------------------------- | |
Echo. | |
Echo Started : %date% %time% | |
echo Free : %sfreespace% Bytes | |
REM Determine OS Class | |
ver | find "2000" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : Windows 2000 | |
GOTO ver_2000 | |
) | |
for /f "tokens=3*" %%i IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| Find "ProductName"') DO set vers=%%i %%j | |
ver | find "2003" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : %vers% | |
GOTO ver_2003 | |
) | |
echo %vers% | find "Windows XP" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : %vers% | |
GOTO ver_xp | |
) | |
echo %vers% | find "Windows 7" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : %vers% | |
GOTO ver_7 | |
) | |
echo %vers% | find "Windows Server 2008" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : %vers% | |
GOTO ver_2008 | |
) | |
echo %vers% | find "Windows Vista" > nul | |
if %ERRORLEVEL% == 0 ( | |
Echo OS : %vers% | |
GOTO ver_vista | |
) | |
Echo OS : %vers% | |
GOTO ver_unknown | |
:ver_2000 | |
:ver_xp | |
:ver_2003 | |
cd %userprofile% | |
cd .. | |
ECHO. | |
Echo ------------------------------------------------------------------------------- | |
Echo. | |
ECHO Clearing Temporary Files For | |
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO ( | |
ECHO %%G | |
DEL "%%G\Local Settings\Temp\*" /F /S /Q >windex.log 2>nul | |
DEL "%%G\Local Settings\Temporary Internet Files\*" /F /S /Q >windex.log 2>nul | |
) | |
ECHO. | |
GOTO STEP2 | |
:ver_7 | |
:ver_vista | |
:ver_2008 | |
REM TODO: Add an admin check | |
if 1 == 2 ( | |
ECHO. | |
ECHO **** This script requires administrative privledges | |
ECHO. | |
ECHO. | |
Echo Press any key to close ... | |
pause > nul | |
Exit | |
) | |
cd %userprofile% | |
cd .. | |
ECHO. | |
Echo ------------------------------------------------------------------------------- | |
Echo. | |
ECHO Clearing Temporary Files For | |
FOR /F "tokens=*" %%G IN ('DIR /B /AD') DO ( | |
ECHO %%G | |
DEL "%%G\AppData\Local\Temp\*" /F /S /Q >windex.log 2>nul | |
DEL "%%G\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" /F /S /Q >windex.log 2>nul | |
) | |
ECHO. | |
GOTO STEP2 | |
:ver_unknown | |
ECHO. | |
ECHO **** This operating system is either unknown, or unsuported | |
ECHO. | |
ECHO. | |
Echo Press any key to close ... | |
pause > nul | |
Exit | |
:STEP2 | |
REM TODO: Add code to empty bin | |
ECHO Emptying Recyle Bin | |
ECHO. | |
:END | |
:: find total free space | |
for /f "tokens=3 delims= " %%A in ('dir /-c %1 ^|find "Dir(s)"') do ( | |
set efreespace=%%A | |
) | |
set /a cleanedspace = sfreespace-efreespace | |
Echo ------------------------------------------------------------------------------- | |
Echo WINDEX :: Robust Cleanup Script for Windows | |
Echo ------------------------------------------------------------------------------- | |
Echo. | |
echo Finished : %date% %time% | |
echo. | |
echo Free : %efreespace% Bytes | |
echo Cleaned : %cleanedspace% Bytes | |
echo. | |
Echo ------------------------------------------------------------------------------- | |
Echo Press any key to close ... | |
pause > nul | |
EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment