Brilliant! How You Do That? – Check Disk Batch Fun

I’ll be walking you through computer tasks that seem difficult but actually easy to learn.

Today’s Lesson: How To Create A Batch File for Checking Your Hard Drive

The first step is to open the application Notepad.

Since we want the computer to invoke the check disk program, we need to type in the check disk command.

chkdsk

The chkdsk command tells the computer we want to check the hard drive for errors or bad sectors. Now, we need to tell the computer which hard drive we want to check.

chkdsk c:

We can easily stop right here but we can use switches to give more detail instructions.

chkdsk c: /f /x

/f switch is used to fix errors found on the hard drive but doesn’t scan for bad sectors./x switch is used to force the hard drive volume to dismount first if needed. This can be used only for drives formatted in NTFS file system.

Note: Chkdsk will not start until the computer is restarted if the hard drive is currently in use. The hard drive with the main operating system installed will need to be restarted.

chkdsk c: /r /x

You can use the /r switch instead of the /f switch. The /r switch locates bad sectors and attempts to recover readable info. This switch can also fix disk errors so the /f switch is implied in the /r switch.

What if you have more than one hard drive you want to check? Just create another chkdsk command for that volume.

chkdsk d: /f /x
chkdsk c: /r /x

Note: Make sure to put command to check the hard drive with the operation system last. This way the hard drives without an operating system gets checked right away & there isn’t a risk of the computer skipping them.

Let’s play with the echo command. Since check disk won’t be able to scan my C: drive right away, a user prompt will asked if I want to scan the drive the next time the computer restarts. I don’t want to have to enter yes every time so we going to use the echo command to feed an yes to the user prompt.

chkdsk d: /f /xecho y|chkdsk c: /r /x

Note: If you want to feed a no to the user prompt, replace the ‘y’ with ‘n’.

Let’s play with the echo command some more. I want the batch program to display a message before the execute check disk program.

echo Check Disk for Errors
chkdsk d: /f /x
echo y|chkdsk c: /r /x

I have a little pet peeve. The command prompt program displays the command from the batch file before it executes it. I want to turn this off. Let’s type in the echo command again.

Typing in the @ symbol before echo off will turn off displaying the command before executing for entire batch file.
Now, I want the computer to restart automatically after the check disk command is executed.

We use the shutdown command with the /r switch which tells the computer to shut the computer down then restart.

Save the file with the extension .bat. Make sure to change “Save As Type” to “All Files” otherwise the file will be saved as a text file.
You have created a simple batch file to run the check disk program. Woot!

Note: You can either double-check batch file to run check disk or create a scheduled task to run the batch program.