To reduce the size of some of my virtual machines, I often run the Windows cleanup tool to get rid of update artifacts and temporary files. While the `cleanmgr` command has some undocumented options such as `/setup`, `/autoclean` and `/verylowdisk`, I could not achive what I wanted with any combination of these: I wanted to have one command that simply cleans _everything_ without interaction. TL;DR: Put this in a batch file:
```dos
@echo off
set rootkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
for /f "tokens=*" %%K in ('reg query %rootkey%') do >NUL REG add "%%K" /v StateFlags0000 /t REG_DWORD /d 2 /f
cleanmgr /sagerun:0
```
Essentially, this script manually creates the registry keys that would be created by a call to `cleanmgr /sageset:0` and checking all the boxes. It then runs `cleanmgr /sagerun:0` which non-interactively calls `cleanmgr` performing every cleanup task available. Remember to run this as an administrator to remove Windows update artifacts.
<a href="https://blag.nullteilerfrei.de/2018/08/10/cleaning-up-windows-without-interaction/#more-4583" class="more-link">Would you like to have that as PowerShell?</a>
Scenario. You have a Windows 7 key and want to farm a Windows 10 key from it, using the automatic upgrade. Of course, you want to do this in a <a href="https://www.virtualbox.org" target="_blank">VirtualBox</a> ((Side note. If you have a <a href="/2012/03/23/windows-customization/">customized Windows</a>, you possibly need to install <a href="https://www.virtualbox.org/wiki/Download_Old_Builds_4_3_pre24">Virtual Box 4.3.12</a> because anything after that will throw <a href="https://www.virtualbox.org/ticket/13504?cversion=1&cnum_hist=1" target="_blank">an error</a>.)). The first thing you do is, set up a VM with at least 30GB of harddrive. Let's assume that this VM is called <b>Nekarat</b>. This is an outdated pop culture reference, <a href="https://www.google.com/search?q=Nekarat" target="_blank">google it</a>.
In the host system (not the VM), go to your happy place (i.e. <b>cmd.exe</b>) and do this:
```bash
cd c:\Program Files\Oracle\VirtualBox
VBoxManage.exe setextradata Nekarat VBoxInternal/CPUM/CMPXCHG16B 1
```
It will not seem like anything has happened, but trust me, it did. It enables a certain CPU instruction for the virtual machine without whome <a href="http://www.dirkstrauss.com/how-to/virtualbox-compareexchange128-error" target="_blank">the Windows 10 update fails</a>.
Boot the VM. Install Windows and update it completely. Do <b>not</b> install the VirtualBox Guest additions: The display driver is incompatible with the Windows 10 update. Now might be a good time to make a snapshot if you want to upgrade more than one key. Activate Windows. Then, in the VM, add this to the registry, <a href="http://www.filecritic.com/how-to-fix-the-something-happened-0x80070002-0x20016-error-and-upgrade-to-windows-10/" target="_blank">courtesy of filecritic.com</a>:
```text
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade]
"AllowOSUpgrade"=dword:00000001
```
Check for updates, it should now download Windows 10. <a href="https://blag.nullteilerfrei.de/2015/08/13/how-to-farm-the-win10-key-from-a-win7-upgrade-in-virtualbox/#more-3446" class="more-link">Wanna know how to extract the key?</a>