Home Technical Articles XP Automate Chkdsk and Defrag on WinXP machines
Automate Chkdsk and Defrag on WinXP machines PDF Print E-mail
Written by Administrator   

logo_windows.gifWe'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.)

 

Automate Chkdsk and Defrag on WinXP machines

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.

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

Last Updated on Sunday, 24 January 2010 01:14
 
SoluFlex

Login Form



Who's Online

We have 2 guests online

Statistics

Members : 149
Content : 37
Web Links : 6
Content View Hits : 38789