Automating Clean Manager.  


  1. Posts : 17,582
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #1

    Automating Clean Manager.


    I thought I would post this more for information than anything else. It deals with the running of CleanMgr.exe in an Elevated CMD Prompt allowing the Hidden cleanup options to become available.

    I am about to Clean Install and then customise the OS. I decided to write a Batch Script that basically cleans up the OS after ALL the customisation so that it is in a tip top state ready for Imaging.

    One of the options is running CleanMgr in Advanced Mode, which basically gives you ALL the clean up options available, as opposed to the Basic Mode for example because I wanted ALL the boxes Checked. The problem with this, is that it asks for confirmation before continuing by pressing OK, which is NOT ideal as I wanted it fully automated.

    In another Batch Script, I use %ComSpec% /c cleanmgr.exe /sageset:65535 & cleanmgr.exe /sagerun:65535 which is fine, even though it involves me having to press OK, but for that particular scenario it is what I want.

    NOTE:

    • You can use ANY number between 1 and 65535 for /sageset:, but you MUST use the SAME number for /sagerun: in order to use the Preset configuration created by /sageset:.

    Therefore, in order for this process to be automated, you first need to run cleanmgr.exe /sageset:65535 prior to including it in a Batch script. This creates a stored REG entry [ EVERY checkbox has its OWN SubKey ] for the Presets of ALL the selected checkboxes.

    REG file => HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches

    Here is mine after running cleanmgr.exe /sageset:65535, but obviously yours could be different . . .

    Automating Clean Manager.-cleanup.png

    Now, all you need to use in the Batch Script is cleanmgr.exe /sagerun:65535, and because ALL the checkboxes are already Preset, there is NO prompt during processing.

    Basically, once the Presets are configured in the Registry, you just need to run the cleanmgr.exe /sagerun:65535 command.



    Summary:

    Once cleanmgr.exe /sageset:65535 has been run and Preset, you can just use cleanmgr.exe /sagerun:65535 in an Elevated CMD Prompt, in a Batch Script, or in a Shortcut, obviously using the SAME number that you used for /sageset:.



    WARNING:

    THIS WILL ALSO AUTOMATICALLY CLEANUP ANY PARTITIONS ON INTERNAL & EXTERNAL DRIVES.



    Additional Information:

    > CleanMgr - docs.microsoft.com
    > CleanMgr - ss64.com



    I just thought that someone might find this useful if they wanted to automate this process.

    Last edited by Paul Black; 24 Apr 2021 at 08:00.
      My Computer


  2. Posts : 3,796
    Windows 11 Pro, 22H2
       #2

    Good stuff!
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:40.
Find Us




Windows 10 Forums