Solved

Can Disk Cleanup be Automated script?

Posted on 2008-06-13
13
3,613 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
ID: 21783842
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
ID: 21784086
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
ID: 21784329
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
ID: 21787183
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
ID: 21826035
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
ID: 21839518
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:zbox
ID: 21855997
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
ID: 21856118
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
ID: 21856166
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
ID: 31467134
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
ID: 21857049
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
ID: 21857897
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
ID: 21865967
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now