Link to home
Start Free TrialLog in
Avatar of ghelaniabhishek
ghelaniabhishek

asked on

Automate Disk Clean up using vbscript

Could somebody please help me in automating disk cleanup of C drive using a VB script.

The option that I am aware of is as follows

1) cleanmgr.exe /d c: /sageset:11
2) the disk cleanup window will open up for me to choose what all to clear
3) After choosing the options, after I click okay, it will save my preference to registry
4) cleanmgr.exe /sagerun:11
5) running the above command will take the settings from registry and automatically start disk clean up without an user inputs.

I want to automate disk clean up on approximately 100 servers. It is not possible for me to follow the above solution since to implement that I will have to manually run the steps 1, 2 and 3 mentioned above on all 100 servers.

does anybody know how to automate the task entirely, ie without any manual efforts involved??

Any help is appreciated
Avatar of RobSampson
RobSampson
Flag of Australia image

Do you know what and where the settings are stored in the registry?

If so, then it would become:
1) Import registry settings
2) Run cleanmgr.exe /sagerun:11

Regards,

Rob.
There's info on the tool here:
http://support.microsoft.com/kb/315246

Regards,

Rob.
Avatar of ghelaniabhishek
ghelaniabhishek

ASKER

Thanks Rob,

but the question here is not about retrieving settings from registry. That is automatically taken care by sagerun. The problem here is setting the values in registry which as of now can be done using sageset attribute which again needs us to manually select the options we want. Which is not possible for me to do it over 100+ servers

 I suggest you try to run the below two commands, so that you will understand how it works.

cleanmgr.exe /d c: /sageset:11
cleanmgr.exe /sagerun:11
Rob, that url says exactly what I have mentioned. What I want is can I eleminate the step of manually setting up the options for disk cleanup??

 I suggest you try to run the below two commands, so that you will understand how it works.

cleanmgr.exe /d c: /sageset:11
cleanmgr.exe /sagerun:11
OK, so I'll run sageset and see what it puts into the registry, then we can automatically insert those settings for sagerun to read.

Rob.
OK, so it looks like, when you set a "job", it enumerates every key under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches

and adds a DWORD value of
StateFlags####
where #### is the number you give the "job", then it sets that DWORD value to 2

Therefore, if you had a script that would set a DWORD value of 2 to a value name of StateFlags#### for options you want, and a value of 0 for options you don't want, then you should just be able to run
cleanmgr /sagerun:####

and it will pick up those settings.

So, I can knock up a script to put the required options on, for the required job number.....what number do you want, and what options do you want?

Regards,

Rob.
number can be anything and options I want to select all the options available with disk cleanup and drive is C drive.

Downloaded Program Files
Temporary Internet Files
Recycle Bin
Temporary Files
Compress Old Files
Catalog files for the Content indexer
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade.

Regards,

Rob.