Can Disk Cleanup be Automated script?

Hello,

I have a 'batch' file that will automate the CHKDSK, DEFRAG, and DISK CLEANUP commands. However, the DISK CLEANUP step doesnt remove all the files for all the selections in the list. Can there be script written into my existing batch file to allow DISK CLEANUP to configure what files to remove when ran?

I want all temp files removed, compress files, etc. All except the Outlook files, those I don't want removed.

Select from the list all the items you would like to be removed, uncheck Outlook
Click OK to save the changes.
Now, the cleanup configuration is stored in the registry.
Just use cleanmgr /sagerun:50 in the batch files to clean the items you have previously selected

0

zboxAuthor Commented: 2008-06-13

that sounds like it would work. Allow me to add a few more details. I need to get this maintenance batch file to over 800 computers. If possible, I'd like to have this programed all into the batch file.

someone dropped this on me recently, but I don't know how to configure the batch file to run this automatically.

http://www.ss64.com/nt/cleanmgr.htmlAfter you create the registry settings for what you want cleaned and exported them to a file named "cleanmgr.reg" use the attached script:

it looks like the scipt you posted first should do the job
:dskClean
REGEDIT /S cleanmgr.reg <- this will put the settings in the registry
CLEANMGR /sagerun:64 <- this will the clean mrg with the settings above

if you're on a domain just push it as a logoff script maybe or just as a startup program

Hmm, perhaps I should run a few more test. Tonight I'll be working late to push this to several computers to see what the results are. Thanks cybrexus, I'll be back later if everything is okay to confirm the solution.

zbox

0

zboxAuthor Commented: 2008-06-19

about the comments above, this command is part of my script but doesnt give the expected results.

:dskClean
REGEDIT /S cleanmgr.reg
CLEANMGR /sagerun:64

but after it runs, I should be able to go back to cmd prompt and run ' cleanmgr /sageset:64 ' and i should see a popup window that has everything checked except just a few things.

Instead when I run CLEANMGR /SAGESET:64, there is only a couple things checked to clean. This tells me that the "cleanmgr.reg" file im keeping in my folder is not doing what I want it too.

What is needed is a script that will automate, CLEANMGR /sageset:64 and then check the boxes I want it too, THEN run the CLEANMGR /sagerun:64 command. That would work.

is this possible. everything i research online doesn't mention automating the sageset part of it.

Your problem is that when you set for example "StateFlags0001"=dword:00000002 -it corresponds to sageset 1 (number 1) but after that you run sagerun:64 which corresponds to set 64
That's why it doesnt work.
So whether you change "StateFlags0001"=dword:00000002 to "StateFlags0064"=dword:00000002 in your reg file or you run sagerun:1

0

zboxAuthor Commented: 2008-06-24

Hmm. That really sounds like the answer and I want it to be, lol. But I just tried it out. I opened sageset:1 and removed all the checked boxes. Then I closed it and I ran the .reg file. (which should check all the boxes I want it too for sageset:1) Afterwards I opened up the sageset:1 settings again and I see that all the boxes are still left unchecked. So this .reg file is doing nothing for me.

it has to work, I just tried on 2 different machine (1 XP and 1 Vista)
make sure you follow the steps:
1. Run > cmd
2. type cleanmgr /sageset:1
3. uncheck everything
4. click OK
5. paste your exact reg file above in notepad, save it and run it
6. in the same cmd window press the Up arrow key (or just type cleanmgr /sageset:1 again)
7. all the things you have checked in the reg file should be there!!

to be sure you may open regedit and and see if the entries in the reg file exist in the registry

0

zboxAuthor Commented: 2008-06-24

wait your right! I was being a newb. I was typing "cleanmgr sageset:1" and not /sageset:1. I forgot the forward slash.

This should take care of it then. I will accept the above comment as solution, because that answers my question. I will post back results as to whether the script works properly running the .reg file though.

peace

zbox

0

zboxAuthor Commented: 2008-06-24

good eye. thanks again! i'm testing it now to make sure it works when the script is ran from start to finish.

ill say whether it was successful or not back on the additional comments option for this question.

peace

zbox

0

zboxAuthor Commented: 2008-06-24

This was the actual solution by cybrexus, can a moderator change it please.

"cybrexus:Your problem is that when you set for example "StateFlags0001"=dword:00000002 -it corresponds to sageset 1 (number 1) but after that you run sagerun:64 which corresponds to set 64
That's why it doesnt work.
So whether you change "StateFlags0001"=dword:00000002 to "StateFlags0064"=dword:00000002 in your reg file or you run sagerun:1"

Thanks, i accidently accepted the explination of the solution as the solution.

zbox

0

zboxAuthor Commented: 2008-06-24

The answer is no.

You were correct to say that sageset:1 is what was being changed, etc. That was a good solution, however, the script itself is not running the "cleanmgr.reg" file to add the sageset:1 information to the registry.

What's the proper way to use script to execute this file? its the file i mentioned earlier, "cleanmgr.reg" in the same folder as the batch file.

normally REGEDIT /S cleanmgr.reg is the command, there is no other than this one
you can also try REGEDIT cleanmgr.reg without the /S for troubleshooting -this should display a confirmation message before and after importing the file