Discussion Locked

automating chkdsk & dfrg

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I implemented a script I downloaded from techrepublic called chkfrag_defrag.zip. Anyways, the document talks about being able to automate the script with XP's Task Scheduler.

I found that if I don't run the command script from the dos shell, it doesn't appear to run at all. Is there a work around this? The script is as follows:

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

3 replies

by mpage

When you set up your scheduled task, you may need to schedule the Command Interpreter to run, and designate this .CMD file as th file to execute.

First go through the task creation wizard, browse to CMD and set up your schedule. The right click on the properties of your event and add the filename and path to the end of CMD.EXE.

It would look something like:

c:\windows\system32\cmd.exe /windows\system32\config\batch\chkdefragdsk.cmd

Keep in mind if there are spaces in the pathname to your CMD file you need to wrap the whole thing in quotes. Save it and you should be golden.

Matthew M Page
Scholle Corp, Network Services

by kwells1014

I tried this script also, and when it didn't seem to work, I tried the command interactively. The message I get says it can't lock the drive and asks if I want to reschedule this for the next startup. Needless to say, the script doesn't finish.

This discussion is closed to new replies.