Skip to content

Instantly share code, notes, and snippets.

@alst74
Created October 30, 2017 10:12
Show Gist options
  • Save alst74/57e306506e702f7469d517e0d73272fa to your computer and use it in GitHub Desktop.
Save alst74/57e306506e702f7469d517e0d73272fa to your computer and use it in GitHub Desktop.
Windows 2008 R2 disk cleanup
REM AUTHOR JAMES FOX
REM SOURCE http://technet.microsoft.com/en-us/library/ff630161(WS.10).aspx
REM '
REM COMMENTS ON BAT SCRIPT CHANGES: FIXES ADDED TO FIX AN ISSUE WHERE CLEANMGR.EXE DOES NOT EXIST
REM ON WINDOWS SERVER 2008 FIXING ALL EDITIONS LISTED BELOW
REM SUMMARY: TEST FOR EXISTENCE OF SOURCE IF EXE DOES NOT EXIST COPY FROM SOURCE (LOCAL ON SERVER)
REM THIS CAN BE RUN ON ALL SERVER EDITIONS INCLUDING SERVER 2000, 2003, & 2008 32bit, 64bit, and R2 for all
REM '
REM DECLARATIONS
SET SOURCEEXE=""
SET SOURCEMUI=""
REM END DECLARATIONS
REM SETUP TEMPORARY ENVIROMENT VARIABLES FOR COPY PROCESS
SET DCLEANMGR=%systemroot%\System32
SET DCLEANMGRMUI=%systemroot%\System32\en-US
REM WINDOWS 2008 R2 64bit
REM SET PATH TO MUI FILE
if exist %SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui set SOURCEMUI= %SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui
REM SET PATH TO EXE FILE
if exist %SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe set SOURCEEXE=%SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe
REM WINDOWS 2008 64bit
REM SET PATH TO MUI FILE
if exist %SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui set SOURCEMUI=%SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui
REM SET PATH TO EXE FILE
if exist %SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe set SOURCEEXE=%SYSTEMROOT%\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe
REM WINDOWS 2008 32bit
REM SET PATH TO MUI FILE
if exist %SYSTEMROOT%\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui set SOURCEMUI=%SYSTEMROOT%\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui
REM SET PATH TO EXE FILE
if exist %SYSTEMROOT%\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe set SOURCEEXE=%SYSTEMROOT%\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe
REM COPY PROCESS
REM THIS SECTION SHOULD NEVER HAPPEN ON WINDOWS 2003 SERVER BECAUSE CLEANMGR.EXE IS ALWAYS INSTALLED
REM TEST AND COPY IF CLEANMGR.EXE DOES NOT EXIST IN EXPECTED LOCATION COPY FROM SOURCE EXE AND MUI
If not exist %SYSTEMROOT%\SYSTEM32\cleanmgr.exe if exist %SOURCEMUI% copy %SOURCEMUI% %DCLEANMGRMUI%
If not exist %SYSTEMROOT%\SYSTEM32\cleanmgr.exe if exist %SOURCEEXE% copy %SOURCEEXE% %DCLEANMGR%
REM RUN EXE AND CLEAN DRIVE MAX CLEANUP
%SYSTEMROOT%\SYSTEM32\CLEANMGR.EXE /VERYLOWDISK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment