Batch File To Defrag and Check Hard Disk


By: RMT2
August 14, 2011

I would like to offer this code to anyone who often wants to defragment and error-check their hard disks. This will do both unattended without any stops. I would like to say though, use this software at your own risk. It has been successfully tested on Windows XP Home Edition and Professional, but there are no guarantees that this software will work, nor it will not cause problems with your system.

To setup the software, please copy and paste the following code into Notepad:

@echo off
COLOR 0F
TITLE ACDDC
ECHO ACDDC
ECHO -----
ECHO STATUS: CHKDSK scheduling in progress.
ECHO Y | CHKDSK C: /F
CLS
ECHO ACDDC
ECHO -----
ECHO STATUS: CHKDSK scheduling completed, defragmentation in progress.
DEFRAG C: > DEFRAG-C.LOG
CLS
ECHO ACDDC
ECHO -----
ECHO STATUS: Defragmentation completed, computer is restarting to do CHKDSK.
SHUTDOWN.EXE -R -F -T 15

Then click File, Save as..., then save it in any location you wish as ACDDC.BAT then exit notepad.
To run the software, simply double-click the program.

Modifications:
You can setup the software to defragment and error-check more than one drive if you desire. To do so, simply integrate the changes in enlarged font into the code:

@echo off
COLOR 0F
TITLE ACDDC
ECHO ACDDC
ECHO -----
ECHO STATUS: CHKDSK scheduling in progress.
ECHO Y | CHKDSK C: /F
ECHO Y | CHKDSK (Drive Letter Here): /F
CLS
ECHO ACDDC
ECHO -----
ECHO STATUS: CHKDSK scheduling completed, defragmentation in progress.
DEFRAG C: > DEFRAG-C.LOG
DEFRAG (Drive Letter Here): > DEFRAG-(Drive Letter Here).LOG
CLS
ECHO ACDDC
ECHO -----
ECHO STATUS: Defragmentation completed, computer is restarting to do CHKDSK.
SHUTDOWN.EXE -R -F -T 15

Do the same copy and paste as above noted and then save it as ACDDC.BAT and overwrite the original batch file.

I hope this code will make someone's job easier for a long time into the future.


Need more help?
Describe your Problem
Example: Hard Drive Not Detected on My PC

Ask Question