Modern versions of Windows defragment drives during regular maintenance schedules. But if you defragment manually—maybe you keep your PC turned off when not in use—you might appreciate a faster way to access the command.

If you’re using Windows Vista up through Windows 10, you probably don’t need to manually defragment your drives anymore. This especially holds true if you’re using a solid state drive (SSD), which not only need to avoid the excessive wear and tear brought on by the process, but don’t need defragmentation anyway. Windows automatically defragments drives that need it once per week—by default at 1:00 am on Wednesdays. (And it is smart enough not to defragment SSDs at all.)

This automatic maintenance, however, requires that your PC be turned on at that time or at least be able to wake up from sleep for the defrag to happen. If you shut your PC down when you’re not using it, you might need to defragment drives on your own once in a while. Instead of digging through tools to do it, why not add a defragment command right to the context menu you get when you right-click a drive in File Explorer?

RELATED: Do I Really Need to Defrag My PC?

Add Defragment to the Context Menu by Editing the Registry Manually

To add a defragment command to the context menu, you just need to make a couple of quick edits in the Windows Registry.

Standard warning: Registry Editor is a powerful tool and misusing it can render your system unstable or even inoperable. This is a pretty simple hack and as long as you stick to the instructions, you shouldn’t have any problems. That said, if you’ve never worked with it before, consider reading about how to use the Registry Editor before you get started. And definitely back up the Registry (and your computer!) before making changes.

RELATED: Learning to Use the Registry Editor Like a Pro

Open the Registry Editor by hitting Start and typing “regedit.” Press Enter to open Registry Editor and give it permission to make changes to your PC.

In the Registry Editor, use the left sidebar to navigate to the following key:

Next, you’ll create a new key inside the shell key. Right-click the shell key and choose New > Key. Name the new key “runas.”

Now, you’ll change the (Default) value inside the new runas key. With the runas key selected, double-click the (Default) value to open its properties window.

In the properties window, set the value in the “Value data” box to “Defragment” and then click “OK.” This gives the command the name that will appear on the context menu.

Optionally, you can also set the command so that it only appears if you hold Shift down while right-clicking a drive—much the same way that the “Open Command Prompt” command is hidden unless you Shift+right-click a folder. To to that, right-click the runas key and choose New > String Value. Name the new value “Extended.” You don’t need to make any changes to it. Just having that string there will cause the command to be hidden behind Shift key access.

Whether you took the optional step of creating the Extended value or not, the rest of the process is the same. You’ll next need to create a new key inside your runas key. Right-click the runas key and choose New > Key. Name the new key “command.”

Now, you’ll change the (Default) value inside the new command key. With the command key selected, double-click the (Default) value to open its properties window.

The (Default) value specifies the actual command that will run when you select the option on the context menu. For our example, we’re going to call the command prompt defrag command and have it run with the default options, but with the verbose switch on so you can see the output of the command. To do that, type the following text into the “Value data” box and then click “OK.”.

RELATED: Dig Deeper in Windows Defrag via Command Prompt

Since we’re calling the command prompt defrag command, you can also use any of the switches that command supports if you prefer. We’ve got a great guide that digs deeper into the defrag command and covers those additional options.

The changes should take place immediately, so you can exit out of Registry Editor. To test it out, just right-click (or Shift+right-click if you set up that option) any drive  and make sure the “Defragment” command is there.

When you run the command—which can take some time—you should see a command prompt window with the results.

If you want to reverse the changes at any time, just go back into the Registry and delete the runas key that you created. This will automatically delete any values and other keys you created inside the runas key and remove the command from your context menu.

Download Our One-Click Registry Hacks

If you don’t feel like diving into the Registry yourself, we’ve created some registry hacks you can use. The “Add Defrag to Context Menu” hack adds the defragment command to the regular context menu. The “Add Defrag to Shift Context Menu” adds the defragment command to the context menu you get when you use Shift+right-click. And the “Remove Defrag from Context Menu” removes the command no matter which way you added it. All three hacks are included in the following ZIP file. Double-click the one you want to use and click through the prompts.

Defrag Context Menu Hacks

RELATED: How to Make Your Own Windows Registry Hacks

These hacks are really just the runas key, stripped down to the additional keys and values we talked about in the previous section and then exported to a .REG file. Running the hacks just modifies the value. And if you enjoy fiddling with the Registry, it’s worth taking the time to learn how to make your own Registry hacks.