Add “Open Admin Command Prompt” to the Explorer context menu in Windows 10 (with keyboard shortcut)

DK/ May 13, 2019/ Windows

Click here for the TL;DR version. Here is a zipped REG file that you can import in case you don't want to go through all of this yourself. I also included a REG file that removes the options. I also put them into a repo on GitHub.

Does this ever happen to you?

You're trying to open an admin command prompt in Windows 10, and want it to start in the path of an Explorer window that you already have open, but when you Shift+right-click, the option isn't there. You either see Powershell or just the regular command prompt option. Now you're stuck with a lot of copy pasta and wasted time!

Well not anymore!

Hi, DK here with some registry edits. Today, I will show you how to open the admin command prompt in an explorer window with ONLY TWO CLICKS! You read that correctly. TWO CLICKS!

Here's how it works. We are going to add this option for the context menu in the background of the explorer window, on an actual folder, and on a file.

In case you were wondering...

Here are the steps:

WARNING: This procedure involves modifying the Windows registry and modifying permissions. You assume all responsibility for whatever happens. Screwing up anything in here might prevent Windows from starting or working properly. If you are not comfortable with modifying the registry, I would suggest stopping now. If you choose to continue, create a restore point and make a full backup of your machine. Also export the registry keys per the instructions below.

NOTE: You will need to follow Steps 2-9 THREE TIMES! The first time is for the folder context-menu (right-clicking on a folder in an Explorer window), the second time is for the background context-menu (right-clicking on the background of an Explorer window), and the third time is for file context menu (right-clicking on a file in an Explorer window). Just repeat the steps and use the indicated registry path in Step 2 and the indicated command in Step 9.

NOTE 2: These instructions include a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press a to select the option. If you are in a menu with more than one option assigned to a, you will have to press a until the option you want is selected, and then press Enter to select it.

1. Open the Registry Editor by clicking on start and typing: regedit

Click on the Registry Editor option that appears, or press Enter.

Opening the Registry Editor using the start menu

2. Go to the following location using the address bar at the top of the Registry Editor window:

For the folder context-menu: (right-clicking on a folder in an Explorer window)

  • HKEY_CLASSES_ROOT\Directory\shell

For the background context-menu: (right-clicking on the background of an Explorer window):

  • HKEY_CLASSES_ROOT\Directory\Background\shell

For the file context-menu: (right-clicking on a file in an Explorer window):

  • HKEY_CLASSES_ROOT\*\shell

The rest of the instructions will be the same except for the last step.

3. BACK UP THE KEYS THAT WE WILL BE MODIFYING!

Right-click on the folder to which you just navigated, and click Export.

You will need to do this for all of the folders from Step 2.

Choose a location and name the file something that will describe what it is, such as directory_shell_backup.reg or directory_background_shell_backup.reg, and click Save.

4. After completing your export in Step 3, right-click on the shell folder, and select New, and then Key. Replace New Key #1 with runas.

5. Click on the runas folder. You will see a key labeled (Default). Double-click on it, and enter the following into the Value data field, and then click OK:

For the folder context-menu: (right-clicking on a folder in an explorer window)

  • Open in &Admin Command Prompt

For the background context-menu: (right-clicking on the background of an explorer window):

  • Open &Admin Command Prompt here

For the file context-menu: (right-clicking on a file in an Explorer window):

  • Open &Admin Command Prompt at file location

You can be creative as I have been in the image in Step 6 below, as long as you know what the command actually does.

NOTE: The & that appears before "Admin" indicates that the letter that follows it can be used as a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press a to select the option. If you are in a menu with more than one option assigned to a, you will have to press a until the option you want is selected, and then press Enter to select it. You can also move the & to another character or add unique characters so you won't have to press Enter.

6. Right-click on the runas folder, and select New, and then String Value. Enter the following as the name:

  • NoWorkingDirectory
Be creative, but also be careful.

7. Right-click on the runas folder, and select New, and then String Value. Enter the following as the name:

  • Icon

Double-click on it, and enter the following as the value:

  • %windir%\system32\cmd.exe

This will put the Command Prompt icon into the dropdown to the left of the entry.

8. Right-click on the runas folder, and select New, and then Key. Give it the name below, and then click on it:

  • command

9. Double-click the (Default) key, and enter the following into the field:

For the folder context-menu: (right-clicking on a folder in an explorer window)

  • powershell -WindowStyle Hidden "start cmd \"/k cd /d %1\" -v runAs"

For the background context-menu: (right-clicking on the background of an explorer window):

  • powershell -WindowStyle Hidden "start cmd \"/k cd /d %V\" -v runAs"

For the file context-menu: (right-clicking on a file in an Explorer window):

  • powershell -WindowStyle Hidden "start cmd \"/k cd /d %w\" -v runAs"

NOTE: These three commands use different variables for the folder, which is why the command for the folder context-menu ends with $1, the one for the background context-menu ends with $V, and the one for the file context-menu ends with %w

The variable V refers to the path of the Explorer window, rather than the path of the folder that was clicked. I found that variable by looking at other keys under HKEY_CLASSES_ROOT\Directory\Background\shell\cmd and coming to the conclusion that it must be referring to the path of the window. Much later, I looked up this list of shell command variables.

TL;DR

Here is a zipped REG file that you can import in case you don't want to go through all of this yourself. I also included a REG file that removes the options. I also put them into a repo on GitHub.

NOTE: These instructions include a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press a to select the option. If you are in a menu with more than one option assigned to a, you will have to press a until the option you want is selected, and then press Enter to select it. You can also edit the menu string and move the & to another character or add unique characters so you don't have to press Enter.

You can also just copy the block below and paste it into a new file with the REG extension, such as admin-cmd-prompt-combined.reg.

Download file

View on GitHub

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@="Open &Admin Command Prompt Here"
"NoWorkingDirectory"=""
"Icon"="%windir%\\system32\\cmd.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@="powershell -WindowStyle Hidden \"start cmd \\\"/k cd /d %V\\\" -v runAs\""

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open in &Admin Command Prompt"
"NoWorkingDirectory"=""
"Icon"="%windir%\\system32\\cmd.exe"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="powershell -WindowStyle Hidden \"start cmd \\\"/k cd /d %1\\\" -v runAs\""

[HKEY_CLASSES_ROOT\*\shell\1runas]
@="Open &Admin Command Prompt at file location"
"Icon"="%windir%\\system32\\cmd.exe"

[HKEY_CLASSES_ROOT\*\shell\1runas\command]
@="powershell -WindowStyle Hidden \"start cmd \\\"/k cd /d %w\\\" -v runAs\""
"NoWorkingDirectory"=""

Note that if you don't want it to say Open Admin Command Prompt Here, then just change it to something else, like Open Admin Command Prompt Dude. Don't forget to put the & before the character that you want to use as the keyboard shortcut!

In either case, double-click the REG file (either the one you created or the one in the ZIP file) to add the entries to the registry.

That's it!

Now you should be able to open the admin command prompt from the context-menu of any explorer folder or window. If you don't see it right away, try rebooting.

Here is a list of all of the resources I used while researching and implementing this solution: