Thursday, March 4, 2010

Windows XP: How to Run Automated Checkdisk From a Batch File?

If you have a lot of partitions and you want to run checkdisk on all of them, instead of doing it individually for each drive, you can use this batch file.
Copy and paste the following code into a notepad and save the file with a .bat extension.
Eg. “checkdisk.bat“.
  1. When saving the file, use the quotation marks in the file name so notepad doesn’t assign the default .txt extension.
  2. Run this batch file(double click it to run) from any drive other than your windows drive.
  3. Edit(right click the batch file > edit) the file depending on how many partitions you have.
  4. Your windows drive should be the very first.
  5. In the below code my windows drive is C: so I started with ECHO Y| chkdsk C: /F
  6. Got it? good. If not good luck.
Code:

@ECHO OFF
TITLE CHECK DISK
COLOR 9F
ECHO ================
ECHO Checking Drive C
ECHO ================
ECHO.
ECHO.
ECHO Y| chkdsk C: /F
ECHO.
ECHO.
ECHO ================
ECHO Checking Drive D
ECHO ================
ECHO.
ECHO.
ECHO N > check.TXT
ECHO Y >> check.TXT
TYPE check.TXT| chkdsk D: /F
ECHO.
ECHO.
ECHO ================
ECHO Checking Drive E
ECHO ================
ECHO.
ECHO.
TYPE check.TXT| chkdsk E: /F
DEL check.TXT
ECHO.
ECHO.
PAUSE
PAUSE
Eg. If you have another drive F then in your batch file,
after this line TYPE check.TXT| chkdsk E: /F and
before this line DEL check.TXT add the following code and so on for as many drives as you have.
Code:

ECHO.
ECHO.
ECHO ================
ECHO Checking Drive F
ECHO ================
ECHO.
ECHO.
TYPE check.TXT| chkdsk F: /F
Restart your comp so checkdisk can check the drives that were in use. If you want you can also copy and paste the below given code to the end of your batch file to restart your comp automatically.
Code:

cls
shutdown -r -f -t 180 -c "The computer will restart in 3 minutes when the timer counts backwards to zero. Please exit all running programs. To abort this shutdown Go to Start > Run > type cmd > Hit enter > type shutdown -a > hit enter."
1. In shutdown -r -f -t 180, 180 means seconds. So it means your comp will restart in 3 minutes. You can change 180 to 0 for an instant restart.
2. Recommend running checkdisk before and after a manual defrag.

No comments:

Post a Comment