Disk Clean Up to Run in Background

Hello All,

Can you help me to make the Disk Clean Up Procedure runs in the background? I am using the script below which runs as a logged in user, but it shows a GUI (showing the Disk Cleanup Progress Bar) which might accidentally close by a user once we executed the procedure. Also, can we delete the following Data/Logs using this procedure:

Setup Log Files
Downloaded Program Files
Temporary Internet Files
System archived Windows Error Reporting
System queued Windows Error Reporting
System created temporary Windows Error
Delivery Optimization Files
Temporary Files

EXCEPT Recycle Bin.

Below is the script that I am using.

import os
print(‘Disk Cleanup has been completed.’)
clean=os.popen(‘cleanmgr.exe /sagerun:1’).read() # should works in both 32-bit and 64-bit
print(clean) # cleanmgr run from gui and don’t return anything, this should be empty


Hi @apanelo

Thank you for contacting us on your script request. We will update you once completed.


Hello @mkannan,

Thank you :).

Yes, I would like this too. Has it been added to the list? I still only see the regular cleanup.

Hi @planit

We are ensuring the script function. We will update you once completed


Hello @mkannan ,

I hope you are doing great. I just wanted to know what is the current status of my request.

Thank you,

Hi @apanelo
We could not able to create the script to perform the disk clean without any interaction using the built-in tool like “cleanmgr.exe /sagerun:1”.
Because the file categories should be selected for deletion.

But Please refer this script, It will delete all files that fall under following categories.

1.Setup Log Files
2.Downloaded Program Files
3.Temporary Internet Files
4.System archived Windows Error Reporting
5.System queued Windows Error Reporting
6.System created temporary Windows Error
7.Delivery Optimization Files
8.Temporary Files