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…


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


Manual Registry Hack

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



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.


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

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 06/25/08

Comments (16)

  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.



  4. The Geek


    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


    Will get on that.

  10. Motor Mike

    Does this work for network drives as well?

  11. brandon

    hey thnx alot for the helpful little tweaks
    greatly appreciated

  12. Spacegold

    It’s a nice little trick and I would jump on it in a second if Vista did not employ automatic defrag every week. On the rare occasion when a person might need to defrag a specific disk, it is easily done from the control panel.

  13. bw

    I successfully implemented this reg hack, but the CMD prompt closes afterwards (automatically). Is there a way to have the CMD prompt stay open so I can review the results?

    Thanks Geek, not only for a great hack, but a great site.


  14. Smi

    Nice! I have added -u switch at the end of defrag %1 -v to show me progress. Thanks

  15. Nymphilis

    Great Tip!!!

    Btw heads up, when accessing this page i was hit with a popup virus/trojan, i task killed the window rather then hitting the “x” but still scanning, please check your website for malware…i love this site and would hate to see it get hit with anything big*(or small to the simple minded computer people)


  16. thomas

    i wont lie, i looked at all 50 hacks, and wow i am way over my head in even reading this stuff and trying to understand it,lol. what i really need is a hack for when i put in my resumes to companies online that they will look the best and always stay at the top of the list so they constantly see mine,lol. i doubt its possible tho.

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!