8

How do I add a menu item to my context menu to open up powershell (or any other arbitary application) when I right-click inside Windows Explorer?

I found tons of links on how to add menu items when doing this: (selecting a folder; example link)

right-clicking a folder

...but couldn't find any instructions on how to add menu items when doing this: (not selecting a folder or file)

not right-clicking anything

I did find this and tried adding powershell to HKEY_CLASSES_ROOT\Directory\Background\shell\, (loosely based on the instructions I found and linked above) but it didn't work for me.

I'm running Windows 7, by the way. Also, I'm currently interested in adding only PowerShell, but I'd prefer a general solution I can apply to add any program to the context menu.

0

3 Answers 3

5

Steps:

  1. Save this code in a file called powershell.reg:

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell]
    @="&Powershell"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command]
    @="C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
    
  2. If your Windows folder is not C:\WINDOWS, change the script accordingly. Make sure to use double backslashes.

  3. Double-click powershell.reg.

  4. When asked if you're sure, click Yes.

  5. Click OK.

This is the result:

screenshot

This works, of course, for any program. Just replace every occurrence of Powershell and the full path of powershell.exe by, e.g., Windows Calculator and C:\\WINDOWS\\system32\\calc.exe.

5

The basic process is just as Dennis described in his answer.

The addition I have to make allow you to customize the icon displayed for the menu and also specify the placement of the item in the context menu.

Context Menu Icon

  1. Add an Icon String Value entry under the HKEY_CLASSES_ROOT\Directory\Background\shell\PowerShell key.
  2. Specify the path to the icon for the item.

Position of Menu Item

  1. Add a Position String Value entry under the HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell key.
  2. Specify Top to place the item at the top of the menu or Bottom to place it at the bottom of the menu.

Below is a registry script of the procedures I described above. Paste it into notepad and save it as powershell.reg (or anything else but with the .reg extension). Then import it into the your system registry to add the menu item.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell]
@="&Powershell"
"Icon"="C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
"Position"="Top"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command]
@="C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"

If you're feeling geeky enough and want to put multiple programs in a cascading menu, you can follow the instructions here.

3
  • I am trying to do the same thing, the problem is as in the image in the question above, the file path shows it is a "Library" and these Registry additions only seem to work when in a folder not accessed by "Library"....any ideas how to get it to work with Library being in the file path?
    – JasonDavis
    Jan 13, 2013 at 3:01
  • @JasonDavis: Replace Directory in HKEY_CLASSES_ROOT\Directory\Background with LibraryFolder (i.e.: [HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\Powershell] and [HKEY_CLASSES_ROOT\LibraryFolder\Background\shell\Powershell\command]). The rest of the process is the same. Dec 12, 2015 at 7:30
  • @AlexEssilfie Great find on the Position value! I've been editing the registry for years and never come across it. How did you come across it, and do you know of any resources that list all similar possible values for context menu-related? Would really appreciate it. Aug 20, 2017 at 23:50
3

Resurrecting this for the sake of completeness, as I just went through this while reinstalling my machine.

[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit cd '%1'"

[HKEY_CLASSES_ROOT\Directory\background\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit cd '%v'"

The first registry key is for the right click on a folder and the second registry key corresponds to right clicking while selecting nothing.

Not the answer you're looking for? Browse other questions tagged .