Add Defragment Now to the right-click menu - gHacks Tech News

Add Defragment Now to the right-click menu

Defragmenting the hard drives of your computer is important on PC systems where programs are installed and uninstalled frequently, or where other read and write operations of files are handled regularly. This can be for instance the case on a drive that is used to save P2P files.

In a perfect world, files would be written contiguously on the hard drive. In the world of Windows they are not, at least not all of the time. Think of the hard drive as a list of blocks that you can fill with data. When the hard drive is new, files can be written in a single block on the drive, but once files get deleted regularly, blocks of different sizes for write operations appear. It then happens that a block is not large enough to contain a file that needs to be written on the hard drive. That's when the contents of the file are split among multiple blocks, and that is what is called fragmentation.

Defragmentation resolves those issues by merging files together again on the hard drive so that the hard drive does not need to jump around to load the file.

I'm lazy. I do not want to right-click the drive, select Properties, change to the Tools tab and click on Defragment Now. Fortunately for users like me there is a workaround that adds the option to defragment your hard drive to the right-click menu of all connected hard drives and partitions.

To make this change, all that is needed is to add a single key to the Windows registry. Once done, the new option appears whenever you right-click a drive in Windows Explorer.

  1. Open your Registry in the following way: Use the Windows-R key to open the run box, type regedit in the box that opens up and hit the enter key.
  2. Navigate to the key HKEY_CLASSES_ROOT\Drive\shell using the folder structure on the left.
  3. If the shell key is missing create it by right-clicking on Drive and selecting NEW > KEY and enter the name shell.
  4. Create a subkey the same way and name it defragnow.
  5. Double-click the default value on the left side and add a name for the command that will appear in the right-click menu, defrag for instance.
  6. Right-click on defragnow and create a new subkey called command. Double-Click the Default entry on the left side again and enter the following value: defrag.exe %1 -v

Once done close the registry and right-click a drive to see if the new option defrag appears. If it does test it with a left-click on the option. A new window should appear on the screen and the defragmentation of the drive should start automatically.

Update: Defragmentation is automatically scheduled on Windows 7 and newer versions of the Windows operating system so that you do not need to run manual runs anymore.

Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. Bordone said on November 3, 2006 at 3:55 am
    Reply

    I’m even lazier. In XP you can use task scheduler to setup a weekly job of defragging your disks (2am on Mon-Tues is a good time).

    Follow the wizard for a new task in the taskscheduler point it to %windir%\system32\defrag.exe and set up your time. Go into the task properties and add the following:
    defrag.exe c: -f -v
    c: is your drive letter
    -f forces the defrag
    -v is verbose
    You can always do a defrag /? from the command line to find other options.

  2. levitra said on January 4, 2007 at 4:33 am
    Reply

    Casa bunqo inqubitum lorem!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.