How do I install Disk Cleanup on Windows 2012 server without installing the Desktop Experience?
"Disk Cleanup" only requires 2 files to work (together, less than 260KB)
"cleanmgr.exe" for your platform, and a "cleanmgr.exe.mui" for your locale. They are already on your machine in sub-folders under "%SystemRoot%\WinSxS".
First, search under the "%SystemRoot%\WinSxS" folder for "cleanmgr.exe". You will likely find files in the "amd64", "wow64", and "x86" folders. I chose "amd64" for both files on my Windows Server 2012 Standard x64 installation.
Copy those 2 files to these locations:
- %SystemRoot%\System32\cleanmgr.exe
- %SystemRoot%\System32\en-US\cleanmgr.exe.mui
(I would assume that, if you're using a different locale, WinSxS would have more choices, and you'd have to copy the .mui file to the sub-folder for that locale.)
Technically, you're done at this point. Run "cleanmgr.exe" as Administrator if you want it to show you everything it can clean (including stale Windows Updates stored in WinSxS, which are now an option in Win2012).
If you want more "GUI-ness", proceed...
To get your new "Disk Cleanup" into the Start menu, create a shortcut to the "cleanmgr.exe" file. Put the new shortcut in the "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Administrative Tools" folder; name it "Disk Cleanup". Now, when in the Start menu, you can just type "Disk Cleanup", and you'll have the option to start it as Administrator at the outset.
To get "Disk Cleanup" to show up as a button on a disk drive's Properties dialog box, you have to change the registry to add a new key and "Expandable String Value". Create a new .reg text file and paste in the following:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\cleanuppath]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6c,00,\
65,00,61,00,6e,00,6d,00,67,00,72,00,2e,00,65,00,78,00,65,00,20,00,2f,00,44,\
00,20,00,25,00,63,00,00,00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\cleanuppath]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,00,6c,00,\
65,00,61,00,6e,00,6d,00,67,00,72,00,2e,00,65,00,78,00,65,00,20,00,2f,00,44,\
00,20,00,25,00,63,00,00,00
The hex string is "%SystemRoot%\System32\cleanmgr.exe /D %c", in case you want to add this manually. For me, I only needed the first key to be added. The second key was just another place I found the setting located. FYI, there were 2 other places in the registry that dealt with "cleanmgr.exe", but luckily they didn't matter for this, since they used some ClassID GUID stuff.
Related videos on Youtube
Granger
Updated on September 18, 2022Comments
-
Granger over 1 year
The issue is simply that I want to do the best I can to clean-up/compact a VM's .vhdx drive before running the Optimize-VHD cmdlet. It's nice to use Microsoft's Disk Cleanup utility. The problem is that it's not installed by default.
The official way to get it is to use "Add Roles and Features" and add the "Desktop Experience" feature. There are unwanted side-effects to that, among which that the feature additionally requires the "Media Foundation" and "Ink and Handwriting" features. I just want "Disk Cleanup".
-
Michael Hampton over 10 yearsRemember, unlike in 2008 Desktop Experience is removable and you can go back to Server Core.
-
Granger over 10 yearsTrue: That's partly how I figured this out. :) But now I don't have to reboot my server to "install" it.
-
James L. over 8 yearsAlso, delete all log files under
c:\windows\logs\cbs
. Some users report 20+ GB consumed by these logs. These logs expand each time you run Disk Cleanup or Windows Updates (and who knows what else). If you can't delete them, stop theTrustedInstaller
service and try again.
-
-
James L. over 8 yearsIf you're on a 64bit OS, then there are two sets of files in the
winsxs
folder. Theamd64
files go inc:\windows\system32
andc:\windows\system32\en-US
, and thex86
files go inc:\windows\syswow64
andc:\windows\syswow64\en-US
. -
Yama about 8 yearsIt seems that this method isn't complete. Doing this doesn't seem to give me the option to remove "Previous Windows Installations". Installing Desktop Experience on a given host does.. I'll check a few more servers to confirm this.
-
Ale over 7 yearsTried this on Win2012 R2, but Windows tells me that it doesn't support running old 16-bit applications (!). Looked into the EXE, it appears to be compressed, but there seems to be no official utility to extract it. I found this one on GitHub, it worked fine on my installation and I got the cleanup wizard working: github.com/hfiref0x/SXSEXP
-
jitbit over 5 yearsworks only partially (no "clean up system files" option)