When we right click on a folder we see lot of menu options. Wondering how can we add our own program in that list… It can be done easily like 1,2,3 go… I guess it will helpful for peoples who want to execute batch flies from multiple random folders frequently or want to customize their right click menu.
We are going to accomplish this by modifying the registry.
Windows registry is like a heart of windows operating system, No matter what we do on the computer it has to consult the registry to either get or put info. And of-course when we right click on folder/files/ to populate the context menu it has to consult the registry.
HKEY_CLASSES_ROOT is the root key which holds all the information about file associations and stuffs. When we right click on a file/folder windows looks for that file type from this root key and then executes the command defined there. There is a lot of things about this key, lets not go deep and come to our point right click on folder. Well, when we right click on any folder windows quickly reads HKEY_CLASSES_ROOT\directory\shell and HKEY_CLASSES_ROOT\folder\shell keys. Under these keys there are some sub keys which we see like Find, Open, Explore.
Each subkey under Shell has a name, a default value for that keyname, a subkey Command and a default value for Command. The default value of Command key is the one which will get executed when you select your menu option from Right click menu.
Alright, Seems confusion. Lets do it and see yourself what I mean.
Step 1. Open registry editor by typing regedit in run dialog box or from a command prompt.
Step 2. Navigate to HKEY_CLASSES_ROOT\Directory\Shell
Step 3. Right click on this key and create a new key. Name it anything you like. Does not matter.
Step 4. Once the ley is created you will see a value named Default in right pane of registry editor window. Double click on it and type the Text you want to be appeared in right click menu,it could be something like RunMyScript or anything like that. I used Run Script Chandra for keyname and value as well. So now we have a key name HKEY_CLASSES_ROOT\Directory\shell\Chandra
Step 5. Now create a new subkey under the newly created key name and put the name as Command. The name HAS to be Command ,anything else wont work for us.So now we have in this example HKEY_CLASSES_ROOT\Directory\shell\chandra\command
Step 6. Now click on the newly created keyname,in my case chandra. You will see a value default. This is the one we are looking for. Anything you put here will get executed when you select this menu from right click.put “cmd.exe /k echo %1” for example.
Here is some tips for you to follow!
1. the folder on which you right clicked will use the varible %1.
2. If you want your batch file to run then modify your batch file so it use %1 as working directory.
3. Cmd.exe /c will close the command prompt window once finished.
4. Cmd.exe /k will leave the command window open once the following command is finished executing.
YOu can put any windows recognized command combination in step 6.
If you want your batch file to run then put cmd.exe /c “yourbatchfilepath”
Note: as said registry is the heart of windows and playing with it may cause serious issues so make sure to back the registry before editing.