Skip to content

Instantly share code, notes, and snippets.

@Jeff-Lewis
Created December 5, 2016 15:37
Show Gist options
  • Select an option

  • Save Jeff-Lewis/3e7f28e5caec8709fa59420b230e1873 to your computer and use it in GitHub Desktop.

Select an option

Save Jeff-Lewis/3e7f28e5caec8709fa59420b230e1873 to your computer and use it in GitHub Desktop.
Windows_Server_Copy_Disk_Cleanup
Simple Disk Cleanup Server "Fix" v. 1.1
Date: 5.12.2014
http://www.null-byte.org/development/missing-disc-cleanup-utility-in-windows-server-fix/
Simple batch script to copy Windows Disk Cleanup tools without the need to install the full Desktop experience on a server, which also requires a reboot.
The script will attempt to detect the operating system and copy the required files (2) to the correct folder. A prompt to execute has been added in the end.
Usage:
1) Extract contents of the ZIP file to the servers local disk (Any location works, except UNC paths)
2) Execute script with Admin privileges if you have UAC enabled
You can delete the script once it has completed, it can be deleted.
Please do not provide this Zip file on your own site, but rather reference the source site. This way any updates to this script can be found in the same location.
For any questions or feedback, contact me at info@null-byte.org
http://www.null-byte.org/development/missing-disc-cleanup-utility-in-windows-server-fix/
What's New
v1.1
- Cleaning of code
- W2012 Fix
- Mixed printout messages
@echo off
ver | find "6.0" > nul
if %ERRORLEVEL% == 0 goto detect2008
ver | find "6.1" > nul
if %ERRORLEVEL% == 0 goto ver_2008R2
ver | find "6.2" > nul
if %ERRORLEVEL% == 0 goto ver_2012
ver | find "6.3" > nul
if %ERRORLEVEL% == 0 goto ver_2012R2
if not exist %SystemRoot%\system32\systeminfo.exe goto failed
:failed
echo Windows OS Version not detected.
:detect2008
if exist "%ProgramFiles(x86)%" goto ver_2008x64
else goto ver_2008x86
:ver_2008x86
echo Windows Server 2008 x86 Detected
REM Cleanmgr MUI location
set cleanmgr_mui=C:\Windows\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui
REM Cleanmgr EXE locaiton
set cleanmgr_exe=C:\Windows\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe
goto copy
:ver_2008x64
echo Windows Server 2008 x64 Detected
REM Cleanmgr MUI location
set cleanmgr_mui=C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui
REM Cleanmgr EXE locaiton
set cleanmgr_exe=C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe
goto copy
:ver_2008R2
echo Windows 2008R2 Detected
REM Cleanmgr MUI location
set cleanmgr_mui=C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui
REM Cleanmgr EXE locaiton
set cleanmgr_exe=C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe
goto copy
:ver_2012
echo Windows 2012 Detected
REM Cleanmgr MUI location
set cleanmgr_mui=C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.2.9200.16384_en-us_b6a01752226afbb3\cleanmgr.exe.mui
REM Cleanmgr EXE locaiton
set cleanmgr_exe=C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.2.9200.16384_none_c60dddc5e750072a\cleanmgr.exe
goto copy
:ver_2012R2
echo Windows 2012R2 Detected
REM Cleanmgr MUI location
REM set cleanmgr_mui=C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.3.9600.16384_en-us_4e94cff86c9dcc30\cleanmgr.exe.mui
REM Cleanmgr EXE locaiton
REM set cleanmgr_exe=C:\Windows\WinSxS\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.3.9600.16384_none_5e02966c3182d7a7\cleanmgr.exe
REM goto copy
echo Windows Server 2012R2 does not currently work. No workaround found as of yet.
pause
exit
:copy
echo Copying: Cleanmgr.exe
COPY %cleanmgr_mui% %systemroot%\System32\en-US\cleanmgr.exe.mui
echo Copying: Cleanmgr.exe.mui
COPY %cleanmgr_exe% %systemroot%\System32\cleanmgr.exe
goto shortcut
:shortcut
SET /P ANSWER=Attempt to create start menu shortcut for all users? (Y/N)
if /i {%ANSWER%}=={y} (goto :yesstartmenu)
if /i {%ANSWER%}=={yes} (goto :yesstartmenu)
goto :exit
:yesstartmenu
set location=%~dp0
echo %location%
COPY %location%\DiskCleanup.lnk %ProgramData%\Microsoft\Windows\"Start Menu"\DiskCleanup.lnk
goto :exit
:exit
SET /P ANSWER=Start Disc Cleanup ? (Y/N)
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
exit
:yes
%systemroot%\System32\cleanmgr.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment