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

13 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
  3. Wow, fantastic weblog structure! How lengthy have you ever
    been running a blog for? you made blogging look easy.
    The overall glance of your web site is fantastic, let alone the content!

    2012/12/14
  4. I’m new to building internet sites and I was wanting to know if having your site title related to your content really that critical? I see your title, ” Defrag Script for all Fixed Disks | EnX Blog ” does seem to be spot on with what your website is about but yet, I prefer to keep my title less content descriptive and based more around site branding. Would you think this is a good idea or bad idea? Any kind of assistance would be greatly appreciated.

    2013/03/24
  5. What’s up, I wish for to subscribe for this webpage to take hottest updates, thus where can i do it please assist.

    2013/05/31
  6. San #

    I’m sinedng them to see if they like the whole song you sinedng them to see pretty pictures with the song and its awesomeness doesn’t need help being spread

    2013/07/24
  7. Hi, after reading this remarkable paragraph i am also happy to share my familiarity here with
    colleagues.

    2014/04/27
  8. I love it when folks come together and share thoughts.

    Great site, stick with it!

    2014/05/05
  9. This post will help the internet visitors for setting up new blog or even a blog from start to end.

    2014/05/06
  10. Heya are using WordPress for your blog platform?

    I’m new to the blog world but I’m trying to get started and create my own. Do you require any html coding knowledge to make your own blog?
    Any help would be greatly appreciated!

    2014/05/21
  11. I don’t know whether it’s just me or if everybody else experiencing issues with your blog.
    It appears as if some of the text within your content are running
    off the screen. Can someone else please comment and let me know
    if this is happening to them as well? This may be a
    problem with my web browser because I’ve had this
    happen before. Kudos

    2014/05/23
  12. I’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and engaging, and without a doubt, you have hit the nail on the head.
    The problem is an issue that too few people are speaking intelligently about.
    Now i’m very happy I came across this in my hunt for something relating to this.

    2014/05/27
  13. Pretty component to content. I simply stumbled upon your site and in accession capital to say
    that I acquire actually enjoyed account your blog posts.

    Any way I will be subscribing on your augment and even I success
    you get admission to constantly quickly.

    2014/09/11

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 )

Google photo

You are commenting using your Google 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

%d bloggers like this: