Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Enhancing the “Open Command Prompt here” Shift-Right-Click Context Menu experience

For decades, you’ve been able to hold down [Shift] and Right-Click a folder (or the background of a folder) and get a “Open Command Prompt here” option.

I recently also discovered, that you can open any program using the folder as the current folder by typing the Command (e.g. cmd.exe or powershell.exe) in the Address Bar.

In the Windows 10 Curators Update, the default shell is being changed to PowerShell (“Open PowerShell here”) — in light that PowerShell is a more comprehensive shell than CMD.

Looking into this, I realized two things:

  • Sometimes I want more than just a single shell option in the menu
    • I want CMD, PowerShell, BASH, GIT, etc.
  • With the introduction of UAC in Windows 7, it’s no longer possible to launch one of these shells elevated

Adding additional entries is easy — it just requires additional “shellcommand”  registry entries.

  • The order in the menu is the alpha order of the
  • The menu text is the “shell(default)” REG_SZ text
  • i.e. the menu doesn’t have to be in the alpha order of the menu text
  • Add “&” in the text to specify the keyboard shortbut

The issue is the elevation. If the target EXE isn’t manifested as requiring elevation, you need to use the special verb “runas” to cause the elevation.

That’s great if you’re just adding one entry, but problematic if you want more than one.

What you have to do is to use the “ExtendedSubCommandsKey” concept. This creates a sub-menu.

The great thing about the this concept is the value is “reference”. Meaning it can be shared between the folder (“shell…) and the folder’s background (“backgroundshell…) context menu registrations. Both areas point (reference) the “ContextMenusshell…” area — saving you the need to duplicate the settings.

Within each ContextMenu area (one per shell/prompt), you make the …shell… keys are normal.

In my example below, I have Command Prompt and PowerShell supported, with each supported a verb for non-elevated (“open”) and elevated (“runas”) execution.

  • Command Prompt
    • HKEY_CLASSES_ROOTDirectoryshell1MenuCmd –> Directory\ContextMenus\MenuCmd
    • HKEY_CLASSES_ROOTDirectorybackgroundshell1MenuCmd –> Directory\ContextMenus\MenuCmd
  • PowerShell
    • HKEY_CLASSES_ROOTDirectoryshell2MenuPowerShell –> Directory\ContextMenus\MenuPowerShell
    • HKEY_CLASSES_ROOTDirectorybackgroundshell2MenuPowerShell –> Directory\ContextMenus\MenuPowerShell

What you get is something like this:

Command Prompt menu

PowerShell menu

To make make things look pretty, I’ve set these in the script to add the appropriate icon, etc.

  • Set the application’s icon via the “Icon” REG_SZ on the parent and child nodes
  • Enable the UAC icon via the “HasLUAShield” REG_SZ on the elevated nodes
  • Add the “Extended” REG_SZ on the (old) settings that you want to hide in the Shift Right-Click menu
    • I add these, instead of deleting them, as TrustedInstaller only has access
    • You’ll get a security error when merging the registry file as you don’t have access to modify these if they already exist (not an issue)

ENJOY!

Example: Directory_Prompts.reg

Windows Registry Editor Version 5.00

; Command Prompt

[HKEY_CLASSES_ROOTDirectoryshell1MenuCmd]
"MUIVerb"="Command Prompts"
"Icon"="cmd.exe"
"ExtendedSubCommandsKey"="Directory\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOTDirectorybackgroundshell1MenuCmd]
"MUIVerb"="Command Prompts"
"Icon"="cmd.exe"
"ExtendedSubCommandsKey"="Directory\ContextMenus\MenuCmd"

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuCmdshellopen]
"MUIVerb"="Command Prompt"
"Icon"="cmd.exe"

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuCmdshellopencommand]
@="cmd.exe /s /k pushd "%V""

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuCmdshellrunas]
"MUIVerb"="Command Prompt Elevated"
"Icon"="cmd.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuCmdshellrunascommand]
@="cmd.exe /s /k pushd "%V""


; PowerShell

[HKEY_CLASSES_ROOTDirectoryshell2MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOTDirectorybackgroundshell2MenuPowerShell]
"MUIVerb"="PowerShell Prompts"
"Icon"="powershell.exe"
"ExtendedSubCommandsKey"="Directory\ContextMenus\MenuPowerShell"

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuPowerShellshellopen]
"MUIVerb"="PowerShell"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuPowerShellshellopencommand]
@="powershell.exe -noexit -command Set-Location '%V'"

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuPowerShellshellrunas]
"MUIVerb"="PowerShell Elevated"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOTDirectoryContextMenusMenuPowerShellshellrunascommand]
@="powershell.exe -noexit -command Set-Location '%V'"


; Ensure OS Entries are on the Extended Menu (Shift-Right Click)

[HKEY_CLASSES_ROOTDirectoryshellcmd]
"Extended"=""

[HKEY_CLASSES_ROOTDirectorybackgroundshellcmd]
"Extended"=""

[HKEY_CLASSES_ROOTDirectoryshellPowershell]
"Extended"=""

[HKEY_CLASSES_ROOTDirectorybackgroundshellPowershell]
"Extended"=""

Share the post

Enhancing the “Open Command Prompt here” Shift-Right-Click Context Menu experience

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×