

While cleanmgr.exe is not inherently malicious, its legitimate functionality can be abused for malicious purposes. The following table contains possible examples of cleanmgr.exe being misused. Legal Copyright: Microsoft Corporation.
#CLEANMGR AUTOANSWER WINDOWS#
Product Name: Microsoft Windows Operating System.Subject: CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US.Issuer: CN=Microsoft Windows Production PCA 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US.\BaseNamedObjects\C:*ProgramData*Microsoft*Windows*Caches*cversions.2 File Path: C:\Windows\SysWOW64\cleanmgr.exe.Be sure to include all StateFlagsNNNN values even if they're zero, as omitting a key may result in undefined and possibly undesirable behavior. This requires elevated privileges of course. You can then recreate the keys using a command such as reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files" /v "StateFlags6550" /t REG_DWORD /d 2 /f If you need to recreate the registry keys programmatically, look through each subkey in VolumeCaches for StateFlagsNNNN (where NNNN is your n value, zero-padded to four digits).

The site I linked says 0-65535, as do this Microsoft TechNet article and this Microsoft Support page, but on the system I tested, values above 9999 truncated the least-significant digit, and 65500 indeed overwrote 6550 in my tests. This should run Disk Cleanup with the preset settings automatically, and it will close after it finishes running. Where n is the same number you used with the /SAGESET switch. Now, once you have a system that has these settings saved on it, you can execute Disk Cleanup using those presets by calling cleanmgr.exe /SAGERUN:n You can then export that key (if necessary, to use on other machines) and import it on the machine you wish to run see note 2 at the end for more details. Your settings will be saved in the following registry folder: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches This will open a dialog similar to the standard "Clean up system files" dialog of Disk Cleanup. (where n is any arbitrary number from 0-9999 of your choice - see note 1 at end). You likely want the /SAGESET and /SAGERUN switches.įirst, run the following command with elevated privileges (admin): cleanmgr.exe /SAGESET:n Disk Cleanup (cleanmgr.exe) has a set of poorly-documented command line switches that are decently written up by a third party here.
