Jump to content

Recommended Posts

Posted

I've followed a few guides to create my own 'Disk Clean-Up' scheduled task and everything appears to work as expected.

 

However, the task will not stop running....

 

The process is the usual:

 

Admin CMD prompt

 

cleanmgr.exe /sageset:1

 

Choose options

 

Create Scheduled task

 

Program/script field type: C:\Windows\system32\cleanmgr.exe

 

In the Add Arguments field type: /sagerun:1

 

This works and kicks off the Disk Clean-up but then the 'Task' carries on running.

 

I don't think the Disk Clean-up is still running as I can see that start and end in the Disk section of 'Resource Monitor', just the 'Task' doesn't end.

 

It may not be a big deal and there are obviously workarounds like setting it to end the task after 'X' hours, but I don't want to end it prematurely and I'd also like to know what's causing it.

 

Just to say if there are any inbuilt disk clean scheduled tasks they are not doing a great job, as I found 8GB of Windows Update Cleanup...

  • 1 month later...
Posted (edited)

This is also happening for us, same setup. Running the task on Server 2019 and Server 2022 has same result.

 

Seems to be doing the job but not returning the completion result to the task. For us, CleanMgr.exe is left running and idle.

 

If we run the task in PowerShell a CleanMgr window appears and runs the sagerun process as expected in about 2 minutes (as it's already clean). But running from a scheduled task results in CleanMgr.exe being orphaned idle and task never ends cleanly.

 

Did some work today and have tried adding the command as a Task action directly, as well as having a PowerShell script (.ps1) running with CleanMgr command in there. No joy, same result for both.

 

I also tried excluding Windows Updates and Microsoft Defender targets as those take the longest to run when we do it with GUI visible. Manually run command with GUI popup works: Task with hidden GUI does not end properly though.

 

 

Our PowerShell manual command runs as a user, the task runs as system.

Any solutions or other suggestions welcomed :)

Edited by cstreet
Posted

Note: Just tried running the Task as a user, Administrator on the server, same result I'm afraid. CleanMgr fails to end/close which stalls the task as well.

 

Closing the CleanMgr.exe process in task manager works and the task can also be ended by simple right click and end (or by setting the task to end after x minutes). It's just not a clean end! Ironic?

 

If you're using a PowerShell script action started by a task, ending the task does NOT close CleanMgr.exe. You must start CleanMgr.exe as a direct action of the task in order for it to be terminated by the task controls.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...