How do you add an item to the context menu of a folder?

8

5

I know how to add a context menu for when you click on an actual folder:

[HKEY_CLASSES_ROOT\Directory\shell\commandNameHere]

but what about clicking on nothing in a folder?

like I make a new folder on my desktop, double click to enter the folder, then right click on nothing (the folder is empty), now I want my context menu to appear in this situation.

xero

Posted 2012-05-01T16:54:40.427

Reputation: 81

I think the key you want is HKEY_CLASSES_ROOT\Directory\Background – Andrew Lambert – 2012-05-01T18:38:16.117

1thanx @Amazed that was really close...

it is actually: [HKEY_CLASSES_ROOT\Directory\Background\shell\commandNameHere] – xero – 2012-05-01T18:54:07.490

5solved for anyone interested here's the .REG file to add this functionality to the windows context menu:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Shell] @="none" [HKEY_CLASSES_ROOT\Directory\shell\gitBashHere] [HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere] "Icon"="C:\\icons\\git-gui.ico" "MUIVerb"="git bash here" "Position"="bottom" [HKEY_CLASSES_ROOT\Directory\shell\gitBashHere\command] [HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere\command] @="C:\\Program Files\\Console2\\Console.exe -d %v" – xero – 2012-05-01T19:07:00.827

2It's allowed and encouraged to answer your own questions. If you solved your problem, post an answer and accept it. – Dennis – 2012-06-06T14:12:17.137

Answers

10

For anyone interested, here's the .reg file to add this functionality to the windows context menu:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Shell]
@="none"
[HKEY_CLASSES_ROOT\Directory\shell\gitBashHere]
[HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere]
"Icon"="C:\\icons\\git-gui.ico"
"MUIVerb"="git bash here"
"Position"="bottom" 
[HKEY_CLASSES_ROOT\Directory\shell\gitBashHere\command] 
[HKEY_CLASSES_ROOT\Directory\Background\shell\gitBashHere\command]
@="C:\\Program Files\\Console2\\Console.exe -d %v"

(Taken from xero's comment)

This adds a command to the context menu named "git bash here" with an icon, which opens a console.

The command is added under both:

  • HKEY_CLASSES_ROOT\Directory\shell, the context menu when you right-click on a folder
  • HKEY_CLASSES_ROOT\Directory\background, the context menu when you right-click on the "background" empty space while in a folder

Dennis

Posted 2012-05-01T16:54:40.427

Reputation: 42 934

2Be aware of the value "none" for the default action ('@=') Without this 'none', Windows treats one of the added actions as default, so double clicking on a directory does not longer open the directory but triggers the action - which makes Windows nearly unusable. -> Set 'none' as default action allows to add contextmenu items without changing windows default behaviour. – None – 2015-06-09T07:51:20.800

0

void WriteContextMenu(LPSTR key, LPSTR value) {

HKEY hkey=0; DWORD disp;

if(RegCreateKeyEx(HKEY_CLASSES_ROOT, key, 0, NULL, REP_OPTION_NON_VOLATILE, KEY_WRITE,NULL, &hkey, &disp)!=ERROR_SUCCESS) 

{

     if(RegOpenKey(HKEY_CLASSES_ROOT,key,&hkey)!=ERROR_SUCCESS)
    {   

      cout<<"Unable to open Registry"<<key;

        }

}if(RegSetValueEx(hkey,TEXT(""),0,REG_SZ,(LPBYTE)value, strlen(value)*sizeof(char))!=ERROR_SUCCESS)

{

   RegCloseKey(hkey);

       cout<<"Unable to set Registry Value ";

} else{

   cout<<value<<" value has set"<<endl;
}
}int main(){LPSTR key="Folder\\shell\\Testing_App"; 

 LPSTR valueKey="Menu_Title";

 LPSTR Subkey="Folder\\shell\\Testing_App\\command";


/*Here put the path or action you want to perform like you want to
    open cmd  on your context menu so the value id */

    LPSTR valueSubKey="cmd.exe";

    WriteContextMenu(key, ValueKey); 
    WriteContextMenu(Subkey, ValueSubKey);

return 0;}

Kashif Meo

Posted 2012-05-01T16:54:40.427

Reputation: 1

this will show your context menu on all folders ... when you compile this code so make sure you have administrative privileges.. Hope this code will be helpful for you – Kashif Meo – 2016-04-19T10:53:55.073

1Could you [edit] your answer to explain a little more what your code does? – Burgi – 2016-04-19T13:49:25.357

While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill – 2016-04-20T08:48:24.957

actually this code will do just create a new key for context menu. key and subkey also their values respectively. when this code compiled and run then on every folder it will show that context menu... – Kashif Meo – 2016-04-20T13:08:33.007

but I think question req is changed .. it may help him but not the exact solution.. – Kashif Meo – 2016-04-20T13:11:01.190

-2

Here is one solution for all context menus.

https://stackoverflow.com/questions/20449316/how-add-context-menu-item-to-windows-explorer-for-folders/20458056#20458056

But, How to pass multiple directories or files to this context menu as arguments as %1 is taking only one and when we ctrl+click multiple files, it is opening the executable mutliple times instead of sending all of them as arguments.

user2331760

Posted 2012-05-01T16:54:40.427

Reputation: 1