Skip to content

Defrag Script for all Fixed Disks

Defragging your system is an EXTREMELY important thing to do. A slow performing disk is the number one killer of overall system performance. In my opinion a ”slow” machine is due to POOR disk performance. 

DON’T LET THIS HAPPEN TO YOU!!!

Defrag

‘Mark Torng DEFRAG all fixed disks with VBScript

Const LogFile = “C:\Defrag.log”

Const DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5

Set FSO = CreateObject(“Scripting.FileSystemObject”)
Set Drives = FSO.Drives

For each Drive in Drives
 if Drive.DriveType = 2 then
  RunCmd Drive
 end if
Next

Sub RunCmd(DriveString)
Set WshShell = WScript.CreateObject(“WScript.Shell”)
RunString = “%comspec% /c echo ” & WeekDayName(WeekDay(Now), True) & ” ” & Now & ” ” & DriveString
Return = WshShell.Run(RunString & ” >> ” & LogFile & ” 2>&1″, 0, TRUE)
RunString = “%comspec% /c %WINDIR%\System32\Defrag.exe ” & DriveString & ” -f”
Return = WshShell.Run(RunString & ” >> ” & LogFile & ” 2>&1″, 0, TRUE)
Set WshShell = Nothing
End Sub

As always, you must use the visual basic script extention.

Copy the above, paste into a notepad, and save the file as whateveryouwant.vbs

2 Comments Post a comment
  1. jarrgon #

    I second that. We have had hit on performance due to fragmentation on the PCs in our lab. We use them on a daily basis and at the end of the day they just seem to crawl. It looks like they have to be cleaned at the end of day, daily.

    That disk looks like its got blood cancer. I guess thats what happens when procrastination of maintenance chores happens. But most users arent aware of this problem in the first place.

    2007/09/11
  2. So that this situation never happens again, just run Mark’s defrag script regularly using a Scheduled Task weekly or even nightly depending on your computer usage.

    Peace outside

    2007/09/13

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS

Follow

Get every new post delivered to your Inbox.