Winows 10 Disk Cleanup Automation / Silently Run

morpheus83uk 1 Reputation point
2020-08-12T08:45:50.59+00:00

Hello,

I am trying to automate Disk Cleanup for my Windows 10 infrastructure. So far I have tried all sorts of solutions from the internet such as set it up in Task Scheduler and run it as the local system account. This seems to be hidden but it seems to hang and wait for something. I have tried PSEXEC running as system but this again does the same thing. I have run CLEANMGR /SAGESET:100 on my machine setup the settings I want to run and then exported them from the registry, imported them to another machine rebooted it and done a cleanmgr /SAGERUN:100 but it just seems to do a default run and nothing more and still comes up in front of the user.

Is there any way of getting this working?

Thanks

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Anonymous
    2020-08-13T02:48:08.383+00:00

    Hi
    Some program seems to be interrupting the process,
    You could try performing a Clean Boot, then try automate disk cleanup.
    Specific steps check out: https://www.windowscentral.com/how-automate-disk-cleanup-tool-windows-10

    If it remains hanging, you might need to look into Process Monitor for the exact cause:
    https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

    Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.

    I hope this information above can help you.

    0 comments No comments

  2. morpheus83uk 1 Reputation point
    2020-08-13T09:43:12.51+00:00

    Hello,

    Thank you for the response.

    I will have a look using ProcMon now but just for reference this is what I am using to push to our client machines in case I have done something massively obviously wrong:

    Reg Import DiskCleanupSettings.reg /reg:64
    Reg Import DiskCleanupSettings.reg /reg:32
    schtasks /delete /tn DiskCleanup /f
    schtasks /create /tn DiskCleanup /tr "%windir%\system32\cleanmgr.exe /sagerun:100" /sc once /st "14:40" /RL HIGHEST /RU SYSTEM
    schtasks /run /tn DiskCleanup

    So I have used the SAGESET:100 to get the keys I want and then exported them to be imported to the client machines. And the above is being run as the local system account on the machine. So the SYSTEM account is creating the scheduled task but I get the same results with an admin login.

    I will come back with what I have found.

    Thanks

    0 comments No comments

  3. morpheus83uk 1 Reputation point
    2020-08-13T13:04:54.113+00:00

    Ok so after looking at process monitor the chain of events are broadly speaking:

    13:38:35. Process Start Cleanmgr.exe PID 23336 Parent PID 3060 - Command line: C:\Windows\system32\cleanmgr.exe /sagerun:100 Current directory: C:\WINDOWS\system32\
    13:38:35 Thread Create PID 23336 Parent PID 2932 C:\Windows\system32\cleanmgr.exe C:\Windows\system32\cleanmgr.exe /sagerun:100
    13:38:37 Process Create C:\WINDOWS\TEMP\10D0256A-DEC6-4470-84A1-FABBDCE077B2\dismhost.exe Path: C:\Windows\system32\cleanmgr.exe Command Line: C:\Windows\system32\cleanmgr.exe /sagerun:100
    13:46:11 Process Create C:\Windows\system32\wermgr.exe Path C:\Windows\system32\cleanmgr.exe Command Line: C:\Windows\system32\cleanmgr.exe /sagerun:100

    And the process is still running but not doing anything further. Looking around the same times etc nothing else apart from our proxy is doing anything and that is just Microsoft Teams.

    Thanks


  4. morpheus83uk 1 Reputation point
    2020-09-03T13:30:36+00:00

    Hello,

    Thank you for the response and sorry for the late response also! This is on multiple machines and still even after running SFC /Scannow I have the same issue.

    It seems to run the disk cleanup but not the values I have set but when I check on my machine thy are all there in the correct place. Also the agent running the commands is 32bit only so would this have anything to do with it?

    Thanks


  5. aman kumar 1 Reputation point
    2020-10-14T14:04:56.86+00:00

    Hello I found this thread, it basically says cleanmge.exe needs to interact with desktop. So if you're running task as weather user is logged in or not then cleanmgr.exe will not run until you login into system

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.