How to run Disk Cleanup unattended? (batch command, etc.)

V S Rawat 1 Reputation point

I had posted the same here but someone suggested there that I post here, so repeating here.

Problem of Disk Cleanup taking hours is not the only one, another aspect of the problem is that it has many phases that it goes through sequentially and we cannot skip though that.

  1. When I start it, it takes long time to give the first screen of basic files.
  2. If you chose to clean those basic files, it does so, and closes.
  3. You have to start it afresh to clean system files.
  4. If you want to clean system files, it still starts with basic files cleaning screen, going through entire process again dutifully.
  5. I cannot make it directly go to system file cleaning screen, bypassing basic file cleanup.
  6. For both, basic files, and system files, it first takes hours in figuring out what to clea, then you have to give command, and then it taken another span of hours to clean up.
  7. I cannot make it skip that "calculation" part, and rather directly just clean it, and clean it both, basic and system files in one go.

One method could be that we be allowed to run Disk Cleanup throught some batch file and it runs unattended. We can give the command two times, one for basic files, then for system files, and it does its long steps in the background. We don't have to standby to attend to it. There could be command line options that can tell whether to clean basic files of system files or both, and whether to first calculate, or directly go to cleaning anyway. That will save a lot of time and attention one needs to pay to it.

if it uses dism, are there such options in dism commands to run directly as required above?

If someone knows how to do any of the above (different from default sequence), please share.

How can I run Disk Cleanup unattended as described above?

I am on w8.1-64 bit, but the same problem is there in all windows (7, 10...).

A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,855 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jenny Feng 14,081 Reputation points

    @V S Rawat
    The cleanmgr.exe tool has two important switches: /SAGESET and /SAGERUN
    The way these switches work is you manually run the following command on a particular computer at the cmd prompt:
    cleanmgr.exe /SAGESET:123

    What you can do to automate everything is run the cleanmgr tool with /SAGESET on a single computer. Then evaluate which registry values it created, and then write a script that will create the same registry values.

    For your reference:

    In addition, here are some posts with the similar issue with yours, just for your reference, you can try the method mentioned in them:
    Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.

    Hope above information can help you.


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments