Solved

Can Disk Cleanup be Automated script?

Posted on 2008-06-13
13
3,602 Views
Last Modified: 2010-04-21
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.

Here is the script:
*********************************************************

REM chkdsk and defrag automation

for /F "eol= tokens=1 delims=( " %%i in (DrvLtr.txt) do set DrvLtr=%%i& call :dsKchk

 

:dsKchk

If %DrvLtr% == end goto :eof

chkdsk %DrvLtr%

If not errorlevel 3 goto :defrag

If not exist %DrvLtr%\winnt If not exist %DrvLtr%\windows If not exist %DrvLtr%\pagefile.sys goto :dskchkon

 

:dskchkoff

cd\

%DrvLtr%

echo Y chkdsk /F /R

goto :defrag

 

:dskchkon

chkdsk %DrvLtr% /F /R

 

:defrag

cd\

%DrvLtr%

defrag %DrvLtr% -b

defrag %DrvLtr%

 

:dskClean

REGEDIT /S cleanmgr.reg 

CLEANMGR /sagerun:64

 

:EOF

********************************************************************

Open in new window

0
Comment
Question by:zbox
  • 8
  • 5
13 Comments
 
LVL 7

Expert Comment

by:cybrexus
Comment Utility
Click Start, and then click Run. Type cleanmgr /sageset:50 and click OK

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
 

Author Comment

by:zbox
Comment Utility
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.html
 

After you create the registry settings for what you want cleaned and exported them to a file named "cleanmgr.reg" use the attached script:

Open in new window

0
 
LVL 7

Expert Comment

by:cybrexus
Comment Utility
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
0
 

Author Comment

by:zbox
Comment Utility
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
 

Author Comment

by:zbox
Comment Utility
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.

by the way here is what my "cleanmgr.reg" file looks like below,

thanks
Windows Registry Editor Version 5.00
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches]
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content Indexer Cleaner]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files]

"StateFlags0001"=dword:00000002
 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Offline Files]

"StateFlags0001"=dword:0000000

Open in new window

0
 
LVL 7

Expert Comment

by:cybrexus
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:zbox
Comment Utility
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.

Any other ideas?  Thanks for all you do.

zbox
0
 
LVL 7

Accepted Solution

by:
cybrexus earned 500 total points
Comment Utility
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
 

Author Comment

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

you are absolutely correct cybrexus, sorry I doubted your skills.  haha.

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
 

Author Closing Comment

by:zbox
Comment Utility
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
 

Author Comment

by:zbox
Comment Utility
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
 

Author Comment

by:zbox
Comment Utility
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.

zbox
0
 
LVL 7

Expert Comment

by:cybrexus
Comment Utility
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

and don't forget to change to CLEANMGR /sagerun:1

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now