Subscribe to How-To Geek

Add Defragment to the Right-Click Menu for a Drive

After writing the article last week about how to add Disk Cleanup to the context menu for a drive, I received several requests for how to add another menu item for Defrag instead. With a simple registry hack we can do just that.

After manually applying or downloading the hack, you'll have a new item on the right-click menu for your drives…

image

Which will start up the command-line version of Disk Defragmenter (after accepting the UAC prompt)

image 

Manual Registry Hack

Open up regedit.exe through the start menu search or run box, and then browse down to the following key:

HKEY_CLASSES_ROOT\Drive\shell

image

Create a new key under shell called "runas", and then set the (Default) value to "Defragment". If you want to hide this menu item behind the Shift key right-click menu, then add a new string called Extended with no value.

image

Next, you'll need to create a key called "command" and set the default value to the following, which is the command to run defrag with the default options but show verbose output.

defrag %1 -v

You can alternately choose from one of the other defrag switches here if you'd like.

Downloadable Registry Hack

Simply download, extract, and double-click on either AddDefragToDriveMenu.reg (for the regular menu) or AddDefragToExtendedDriveMenu.reg (to hide behind the Shift key). There's also an included removal script that will remove either one.

Download AddDefragToDriveMenu Registry Hack

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 06/25/08 and tagged with: Windows Vista, Vista Tips & Tweaks

Disclaimer: Many of our articles require making changes to your system. While we fully test and stand by our advice, there is still the potential for problems when making any configuration changes. Please be careful.

Comments (9)

  1. USBman

    As one of those that requested this tweak, I humbly thank you.

    Adding the "runas" piece overcame the administrator requirement, and the "Extended" string is a nice touch (works for the aforementioned previous post on adding Disk Cleanup too!).

    Overall, the kind of elegant solution I've come to expect from your site. Well done.

  2. The Geek

    Glad I could help! =)

  3. Brian

    I sure wanted to try this but without the download.
    Since I have only minimal registry work I was careful to do exactly as you had posted.

    However, when I select defragmenet I get
    "Which user account do you want to run this program."
    I then selected current user.
    But then I get just a flash of the DOS screen and it disappears.

    I have double checked all the registry entries and they look just like the ones you posted. Any idea what I can do to keep the DOS screen from disappearing?

    BTW, I don't have Vista, I am using XP 2nd Edition.

    THANKS

    BRIAN

  4. The Geek

    @Brian

    For XP, you should rename the runas key to something else, like just "defrag". I need to update the post to explain the alternate XP instructions… thanks for mentioning.

  5. abhs94

    Hey Geek,
    This was really helpful
    how do you get to know about such tweaks

  6. Mike's beeps! Hahahahahahahahaha!

    You rock!

  7. MikeHigham

    You rock! Thanks!

  8. Mike Higham

    Could you please do one for Check Disk as well?

  9. The Geek

    @Mike

    Will get on that.


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
Popular Articles

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.