Disk Cleanup (cleanmgr) won't close at end until the mouse moves

Anonymous
2024-09-29T00:22:38+00:00

I have a scheduled task on my Windows servers to run Disk Cleanup via "cleanmgr /sagerun:1" and it works just fine except it never ends. Eventually it hits the time limit I set in Task Scheduler and its forced close but this seams like a bug. If I run it from the command line in an interactive session, I think I see the problem. Disk Cleanup runs but when the progress bar gets to 100%, it just hangs. Simply moving the mouse gets it to close as it should. I'm thinking this is why it won't end on it's own when run as a scheduled task - there's no mouse to move.

Windows Server Remote and virtual desktops

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Anonymous
    2024-09-30T16:56:55+00:00

    Hello,

    Thank you for posting in the Microsoft community forum.

    This phenomenon may be due to the graphical user interface (GUI) not automatically updating after completion, resulting in an application that appears to be in a suspended state.

    You are advised to check the Windows update first to improve system compatibility and stability.

    Also, try to repair system files using the System File Checker (SFC):

    sfc /scannow
    

    Wait for the scan to complete and restart the computer. 

    I hope this helps. If you have any follow-up questions, please contact us.

    Best regards

    Jacen

    0 comments No comments
  2. Anonymous
    2024-09-30T17:06:43+00:00

    Thank you for your reply. This isn't a lack of display refresh. Task manager still shows the process running with 0% CPU and about 5 MB RAM. This has been an issue for years spanning Server 2016 - 2022 and perhaps even more.

    3 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2024-12-13T07:09:12+00:00

    We've been experiencing this issue as well with our Windows 11 Pro workstations. We run an automated batch script with this:

    START /Wait /D "%System32%\" "Running Disk Cleanup..." cleanmgr.exe /d %systemroot% /sagerun:1 
    

    When Disk Cleanup reaches 100% then it just halts and does nothing until someone moves the mouse pointer. We can wait a long time with Disk Cleaner showing "100%" completion, and it just won't close. But then move the mouse pointer one centimeter and suddenly Disk Cleaner closes properly. Since this behavior consistently occurs on just about every Windows 10 and Windows 11 workstation that I've ever come across, this is most certainly a bug in Disk Cleanup.

    Best Regards,

    Chris

    Note: We need to use /sageset:1 to set our custom settings and /sagerun:1 so that cleanmgr.exe runs with those same settings. The /verylowdisk parameter is no viable alternative since that is intended to run cleanmgr.exe only with default settings.

    2 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2024-11-22T08:13:58+00:00

    Hello,

    This interaction may be related to the cleanmgr command itself, I'm not sure about the task you specified earlier for /sageset: n. You might consider using automated batch scripts for Disk Cleanup without interaction.

    If the problem persists, given that it involves Windows commands, I recommend directing your question to the following forums:

    Windows Server - Microsoft Q&A

    The technical experts of this platform will provide more precise and efficient solutions according to your problem environment.

    Reference:

    cleanmgr | Microsoft Learn

    Best regards,

    Jacen

    0 comments No comments
  5. Anonymous
    2024-11-22T09:25:06+00:00

    Same behavior. It gets to the end of cleaning up thumbnails and then it just hangs until I move the mouse.

    1 person found this answer helpful.
    0 comments No comments