How do I install Disk Cleanup on Windows 2012 server without installing the Desktop Experience?
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".
"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.