Novell Home

Automating Hard Drive Defrag and Check Disk on Multiple PCs

Novell Cool Solutions: Tip
By Darrell Eddy

Digg This - Slashdot This

Posted: 12 Jan 2006
 

ENVIRONMENT: This works on Windows XP. I have not tested this on Windows 2000 though.

I needed a way to implement automatic hard drive defrag and check disk on multiple PCs.

SOLUTION: Searching the internet landed me a solution to automate the Check Disk and defrag process. I then created an Application Object to create a scheduled task on associated PCs.

Basically, the app object copies the two needed files to a directory on the root of the C drive of the associated PCs. I use a directory called utils. Then using the AT command, I insert a scheduled task into each system for the command to run once per week on the PC.

Example

Copy the following text to a new text document and name it "Dskchk.cmd":

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

Copy the following text to a new text document and name it "drvltr.txt":

c:
end

You need to include any drive letter that you want checked in the process.

This is the axt file used to create the object (replace SERVER with the name of your server):

AXT_FILE 3.1

[Application Name]
Value=Chkdsk-Defrag

[Application Caption]
Value=Chkdsk-Defrag

[Application Path]
Value=%systemroot%\system32\AT.EXE

[Application Flags]

[Application Parameters]
Value=22:30 /EVERY:W "C:\UTILS\DSKCHK.CMD"

[Application Platform]
Flag=Windows 95
Flag=Windows NT

[File Copy]
Flag=Update Create
Source=\\SERVER\PUBLIC\tools\ChkDsk-Defrag\Dskchk.cmd 
Target=c:\utils\dskchk.cmd

[File Copy]
Flag=Update Create
Source=\\SERVER\PUBLIC\tools\ChkDsk-Defrag\Drvltr.txt 
Target=c:\utils\drvltr.txt

[Filter OS Version]
Type=Windows 95
Major Version=-1
Minor Version=-1
Revision Version=-1
Build Version=-1
Flag=Greater Than or Equal

[Filter OS Version]
Type=Windows NT
Major Version=-1
Minor Version=-1
Revision Version=-1
Build Version=-1
Flag=Greater Than or Equal

[Application Association Flags]
Flag=Launcher

[Application Distribution Rules]
File=DIRU0029.XML
Show Icon=0

If you have any questions you may contact Darrell at eddy@latech.edu


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell