Results 1 to 12 of 12
  1. #1
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts

    Setting up Disk Cleanup in Task Scheduler

    I received an email request for these instructions. I considered that more folks might benefit if I answered in a post for everyone instead of an email to just one. So here goes.

    To setup "\Windows\System32\Cleanmgr.exe /sageset:01" just type that line (without the quotes) on the Start Screen. It will open up Disk Cleanup Settings on the desktop. If you're using a Start Menu with Widows 8 (or using Windows 7) type that line in the Search box or Run box and hit Enter.

    Disk Cleanup Settings.PNG

    Choose the options you want, then click OK (in XP "Compress old files" is an option; don't select that one - it will take forever on the first run). "Sage" is System Agent. There may be other Windows utilities that use it, but the "/sageset" switch is used to choose options/conditions and store them associated with a number. I use "/sageset:01" for Disk Cleanup. You can use any number up to 65535 (I think that's the largest number it will recognize).

    To test it, on the Start Screen (or in the Run or Search box) type "\Windows\System32\Cleanmgr.exe /sagerun:01" (without the quotes) and hit Enter. It will jump to the desktop and run there. The "/sagerun" switch tagged with the correct number runs the options/conditions selected associated with that number.

    If that runs as you wish, you can create a desktop shortcut if you like by using that command line. Also, you can set it up to run automatically using Task Scheduler. Open Task Scheduler either logged into an account in the Administrators group, or right-click and select "Run as administrator". It will open in the Task Scheduler Library.

    Task Scheduler Library.PNG

    In the far right pane, click on "Create Task", and a new task dialog box will open. In the General tab, use the settings as shown here. The dialog box won't look exactly like this (more options will be available depending on which tab you're on), but these are the settings to use:

    Disk Cleanup Task.PNG

    You can name the task whatever you wish, and put in a description if you like. Next, click on the Triggers tab, and use the settings as shown here, just use whatever time you wish:

    Triggers.PNG

    Next click on the Actions tab, and use these settings:

    Actions.PNG

    Next click on the Conditions tab, and use these settings:

    Conditions.PNG

    And finally, click on the Settings tab, and use these.

    Settings.PNG

    If you have a question, post it in a reply, and I'll try to answer it.
    Last edited by bbearren; 2014-04-05 at 18:45. Reason: clarity
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. The Following 3 Users Say Thank You to bbearren For This Useful Post:

    cmptrgy (2014-04-10),Dick-Y (2014-04-06),ruirib (2014-04-07)

  4. #2
    Bronze Lounger Drew1903's Avatar
    Join Date
    Mar 2012
    Location
    Calgary
    Posts
    1,206
    Thanks
    0
    Thanked 92 Times in 71 Posts
    Bruce,

    I have used & recommended this for many years. But, my command line is not the same as what you are suggesting. And, no, I'm not referring to 01 or up to 65535

    I used to use
    cleanmgr /sageset
    and
    cleanmgr /sagerun

    Later & ever since, use
    %SystemRoot%\System32\Cmd.exe /c Cleanmgr /sageset:65535 & Cleanmgr /sagerun:65535

    Which does the whole thing in 1 step instead of 2.

    The difference between your command line & the above are obvious.

    Maybe, you would comment... If one is going to do this via Task Scheduler does the command line need to be what you show in your instructions or can it be the line I have been using when doing this manually?

    And, btw, running it manually, the boxes do not have to be rechecked after the 1st time this clean-up is run. They will hold as initially selected in subsequent runnings. This is not the case for the conventional, built-in Disc Clean-up. Likely you are aware of this. Others may not be. But, as an IT Pro it's my instinct to educate.

    Cheers,
    Drew
    Last edited by Drew1903; 2014-04-06 at 05:12.

  5. #3
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts
    Quote Originally Posted by Drew1903 View Post
    Bruce,

    I have used & recommended this for many years. But, my command line is not the same as what you are suggesting. And, no, I'm not referring to 01 or up to 65535

    I used to use
    cleanmgr /sageset
    and
    cleanmgr /sagerun

    Later & ever since, use
    %SystemRoot%\System32\Cmd.exe /c Cleanmgr /sageset:65535 & Cleanmgr /sagerun:65535

    Which does the whole thing in 1 step instead of 2.

    The difference between your command line & the above are obvious.

    Maybe, you would comment...
    For the benefit of others who might not be familiar with commandline and/or Task Scheduler, I'll stack the two so the differences are more obvious.

    C:\Windows\System32\Cleanmgr.exe /sageset:01
    %SystemRoot%\System32\Cmd.exe /c Cleanmgr /sageset:65535 & Cleanmgr /sagerun:65535


    In the beginning of yours, "%SystemRoot%" equates to "C:\Windows" for most users. The "C:" can be replaced with whichever drive letter holds the Windows folder, if it is not on drive C, but they both do exactly the same thing, which is to begin a path statement.

    "\System32\Cmd.exe" continues the path statement and calls the executable "Cmd.exe" to run. This part of your commandline is not necessary. Cleanmgr.exe is a Windows System executable, will run directly under Windows, and does not have to be run under Cmd.exe. It will run via Cmd.exe, it's just unnecessary.

    Which brings us to the "/c" switch. This switch instructs Cmd.exe to call another command specified by string, execute it, then terminate the command window. This is also unnecessary, as Cleanmgr.exe is a self-terminating executable, so calling Cleanmgr.exe directly will result in Cleanmgr.exe terminating itself once it has completed. As for the rest,

    Quote Originally Posted by bbearren View Post
    To setup "\Windows\System32\Cleanmgr.exe /sageset:01" just type that line (without the quotes) on the Start Screen. It will open up Disk Cleanup Settings on the desktop. If you're using a Start Menu with Widows 8 (or using Windows 7) type that line in the Search box or Run box and hit Enter.

    Choose the options you want, then click OK. The "/sageset" switch is used to choose options/conditions and store them associated with a number. I use "/sageset:01" for Disk Cleanup. You can use any number up to 65535 (I think that's the largest number it will recognize).
    Once selected and stored, there is no need to run "/sageset" again, unless one wishes to change the stored options. So in your commandline, "Cleanmgr /sageset:65535" is no longer necessary after its first use, and can be omitted in all subsequent manual runs.


    Quote Originally Posted by Drew1903 View Post
    If one is going to do this via Task Scheduler does the command line need to be what you show in your instructions or can it be the line I have been using when doing this manually?
    As stated in my tutorial, the options one wishes to use for Disk Cleanup only need to be set once; they are stored via the associated number one has chosen, and are available for subsequent use by calling "/sagerun" together with the associated number. So if one uses "/sageset:01" to choose the options, "/sagerun:01" will use those same options every time Cleanmgr.exe is run in the future using that switch and number combination.

    So, for setting this up in Task Scheduler, just follow the tutorial.

    Actions.PNG


    Quote Originally Posted by Drew1903 View Post
    And, btw, running it manually, the boxes do not have to be rechecked after the 1st time this clean-up is run. They will hold as initially selected in subsequent runnings. This is not the case for the conventional, built-in Disc Clean-up. Likely you are aware of this. Others may not be. But, as an IT Pro it's my instinct to educate.
    Yes, as I stated, once "/sageset" has been run, the options are stored. The unnecessary "/sageset" switch in your commandline is also the reason your commandline will not work in Task Scheduler - it brings up the "Disk Cleanup Settings" dialog box, and while all the options are indeed pre-selected via the previous use of "/sageset:65535", the dialog box won't close; it must be OK'd.

    This is the reason your commandline will cause Task Scheduler to stall - it calls for user input, but Task Scheduler tasks run hidden, the dialog box will not be visible, and so it can't be OK'd. Also, your commandline calls Cmd.exe first, then Cleanmgr.exe via the "/c" switch and the string. Since the dialog box is not visible, Cleanmgr.exe stalls, and since it can't complete the string, Cmd.exe cannot close.

    Following the tutorial will work. The graphics are snipped directly from my Disk Cleanup task in Task Scheduler. It has run this way successfully for well over a dozen years. One may choose a different number for "/sageset" and "/sagerun", or different Triggers, Conditions and/or Settings, but the Actions commandline needs to be entered as shown.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  6. The Following 2 Users Say Thank You to bbearren For This Useful Post:

    doneinbywindows (2014-04-12),ruirib (2014-04-07)

  7. #4
    Bronze Lounger Drew1903's Avatar
    Join Date
    Mar 2012
    Location
    Calgary
    Posts
    1,206
    Thanks
    0
    Thanked 92 Times in 71 Posts
    Bruce,

    I had not said the line I have been using would not work in Task Scheduler. @ that point I had not tried it. Was trying to find out it HAD to be done w/ the line you showed. Sorry for any or the misunderstanding. Configuring Task Scheduler was not the issue. But, certainly cool to have it spelled out for Folks.

    Cheers,
    Drew
    290_Windows8_1.jpg

  8. #5
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts
    Quote Originally Posted by Drew1903 View Post
    I had not said the line I have been using would not work in Task Scheduler.
    The tutorial came about as a result of an email I received. Here's a quote:

    I tried to set it up in Task Scheduler. Please, E-mail me the instructions on how to set up this Task.
    Email or Private Message requests for assistance are in conflict with Rule 10, which states, in part: "Private requests defeat the purpose of the Lounge, which is designed to share information as widely as possible."

    That's why I posted this tutorial, to share this information as widely as possible.


    Quote Originally Posted by Drew1903 View Post
    @ that point I had not tried it. Was trying to find out it HAD to be done w/ the line you showed. ...Configuring Task Scheduler was not the issue.
    How the commandline is written in the Actions tab is a crucial part of configuring Task Scheduler. An incorrectly written commandline will cause the task to fail, but will not trigger any error messages as to the reason for failure being the commandline syntax.

    Your commandline is quite common. A Google search for that exact phrase yields about 405 results. (In the early days, the number 65535 was thought to have special significance; it doesn't). For that reason, I explained in my reply to you how your commandline would cause Task Scheduler to stall, and the necessity for following the tutorial in order to achieve success.

    And the email request I received quoted that same commandline, hence the tutorial for setting up Disk Cleanup in Task Scheduler.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  9. #6
    Bronze Lounger Drew1903's Avatar
    Join Date
    Mar 2012
    Location
    Calgary
    Posts
    1,206
    Thanks
    0
    Thanked 92 Times in 71 Posts
    Bruce,

    Yes, it is common. It was shared w/ me & others by an IT colleague years ago, is how I came to know of it.

    Anyway, just to clarify... I wasn't wanting to use that line but, wanting to know if the shorter line needed to be used in Task Scheduler. And that's a yes so thanks for that.

    Cheers,
    Drew
    290_Windows8_1.jpg

  10. #7
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts
    Quote Originally Posted by Drew1903 View Post
    Yes, it is common. It was shared w/ me & others by an IT colleague years ago, is how I came to know of it.
    I've been using it since my Windows 2000 Professional days; just never used the 65535, always 01, and only ran the /sageset switch once. I was a subscriber to The Langalist, and Fred wrote about it in 2002 - "Sageset Unlocks CleanMgr’s Power By Fred Langa on April 4, 2002 in LangaList Plus" (Fred used /sageset:99).

    I first set it up in Task Scheduler after I upgraded to XP. Here's a link to a Windows Support article on the subject. "The n value can be any integer value from 0 to 65535."


    Quote Originally Posted by Drew1903 View Post
    Anyway, just to clarify... I wasn't wanting to use that line but, wanting to know if the shorter line needed to be used in Task Scheduler.
    Perhaps your phrasing, "can it be the line I have been using", through me off a bit:

    Quote Originally Posted by Drew1903 View Post
    Maybe, you would comment... If one is going to do this via Task Scheduler does the command line need to be what you show in your instructions or can it be the line I have been using when doing this manually?
    The Actions tab graphic in the tutorial clearly shows "C:\Windows\System32\Cleanmgr.exe /sagerun:01".

    At any rate, I'm glad you could learn something. That's what the Lounge was designed for, "to share information as widely as possible."

    Also, answering your questions has helped me to further clarify for other Lounge members and guests the use of Cleanmgr.exe and setting it up in Task Scheduler.

    You're welcome, and thanks to you, as well.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  11. #8
    Bronze Lounger Drew1903's Avatar
    Join Date
    Mar 2012
    Location
    Calgary
    Posts
    1,206
    Thanks
    0
    Thanked 92 Times in 71 Posts
    Bruce, yes, I should have better said, am I able to use it in Task Sched or needs to be, etc, etc?

    That was interesting what you told & the info to which you pointed. I honestly can't recall what year I was turned on to this. Sure is heaps better than the default Disc Clean-up native to the OS. But, yes, since not run from cmd & w/ no End User input...

    Anyway, all set, now. Silly, I never put it in place long ago. I'm the same one who has on occasion extoled the virtue of using TS for things to people, LOL

    Sorry for the misunderstanding. My wording wasn't ideal.

    Cheers,
    Drew
    290_Windows8_1.jpg

  12. #9
    New Lounger
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Looks like a good solution. Is this usable with any free disk cleanup tools?

  13. #10
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts
    Quote Originally Posted by kwangso123 View Post
    Looks like a good solution. Is this usable with any free disk cleanup tools?
    It may be, but I would be hesitant to remove duplicate files. Windows uses a lot of duplicate files that are actually necessary for the OS. And anything that requires user intervention won't work in Task Scheduler, as tasks run hidden, and will stall where user intervention is required.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

  14. #11
    Bronze Lounger Drew1903's Avatar
    Join Date
    Mar 2012
    Location
    Calgary
    Posts
    1,206
    Thanks
    0
    Thanked 92 Times in 71 Posts
    Bruce,

    Clean-up on steroids in Task Scheduler is not stopping or shutting down. Started as scheduled but, every time I check just keeps indicating "running" even if it is several hours later or the next day.

    Cheers,
    Drew
    290_Windows8_1.jpg

  15. #12
    Super Moderator bbearren's Avatar
    Join Date
    Dec 2009
    Location
    Polk County, Florida
    Posts
    2,312
    Thanks
    13
    Thanked 225 Times in 179 Posts
    Quote Originally Posted by Drew1903 View Post
    Clean-up on steroids in Task Scheduler is not stopping or shutting down. Started as scheduled but, every time I check just keeps indicating "running" even if it is several hours later or the next day.
    Open Task Scheduler, highlight your Cleanup task, right click and select properties. Check each tab against the graphics I used in my first post to make sure they match.

    Also, in the Actions tab, the Commandline "C:\Windows\System32\Cleanmgr.exe /sagerun:<yournumber>" (without the quotes) should be entered all in a single line in the Details box. The /sagerun switch should not be put in the "Add arguments (optional):" box.
    Create a new drive image before making system changes, in case you need to start over!

    "Let them that don't want it have memories of not gettin' any." "Gratitude is riches and complaint is poverty and the worst I ever had was wonderful." Brother Dave Gardner "Experience is what you get when you're looking for something else." Sir Thomas Robert Deware. "The problem is not the problem. The problem is your attitude about the problem. Do you understand?" Captain Jack Sparrow.
    Unleash Windows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •