GEGeek 
   I don't reinvent the wheel, I just link to it.                                                                          Control-F To Search This Page!
Cheat Sheets Search Engines Diagnostics Misc Tech

GEGeek's Articles

Home

Windows

Software

How To Guides

Tutorials

Hardware

Security

Linux

GEGeek Articles

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   
 

Automate Chkdsk and Defrag

 

We've developed a batch file that can save you some time by automatically running Chkdsk and Defrag on your Windows XP machines. First, it does a read-only Chkdsk. If Chkdsk sets the errorlevel to 3, meaning that it found errors and needs to be run with the /F (fix) option, the file checks to see whether the systemroot or pagefile exist on the drive. If so, it runs Chkdsk the next time the system is rebooted. If systemroot or pagefile don't exist on the drive, it runs a Chkdsk /F /R now, and then it runs a Defrag -b and a regular Defrag. (The -b switch is an undocumented switch that optimizes the drive for boot.)

 

Using the file

To put the file to work, follow these steps:

1. Copy the code in Listing A.

2. Open Notepad and paste in the code.

3. Save the file as Dskchk.cmd.

4. Create DrvLtr.txt and list the letters of the drives you want checked, with each letter on its own line. Under the last

drive letter, type the word end. For example:

C:

F:

end

5. Put Dskchk.cmd and DrvLtr.txt in the same directory. You can then schedule Dskchk with Task Scheduler or run it manually. Works great. I use it all the time

 

Listing A

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%

:EOF

or

 

If you also want to include an Automatic Disk Cleanup


Click Start - > Run
Type “cleanmgr /sageset:1”
Click the “ok” button

The “Disk Cleanup Settings” windows will appear. Check off the items you want automatically cleaned up

Click the “ok” button

The settings are now saved.

To include “Disk Cleanup” in your automated process, save the command “cleanmgr /sagerun:1” in your batch file.

 

I prefer to use CCleaner, which is free and can be scheduled.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   
   

hit counter