Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a context menu to the Windows Explorer for a Java application?

Tags:

How would one go about adding a submenu item to the windows explorer context menu (like for example 7-Zip does) for a Java application?

like image 563
Thilo Avatar asked Dec 15 '08 23:12

Thilo


People also ask

How do I add to Explorer context menu?

Right-click (or select and hold) on a file or folder to open the context menu. Select Show more options.

Where is Windows context menu?

A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.

How do I change the context menu in File Explorer?

Press the Windows key and R simultaneously, type regedit and press Enter. Navigate to HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers and you will see a series of keys that related to existing menu entries. It is easy to delete any you no longer need access to – just right click a key and select Delete.

How do I add the context menu in Windows 7?

Add Any Program to Context Menu. Open the registry and navigate to the following path: HKEY_CLASSES_ROOT\Directory\Background\shell then right-click on shell and select New > Key. Give the new key the name of the program you're adding to the context menu.


2 Answers

I am aware of two ways to do it. The fancy way is to write a windows shell extension, which is how powerarchiver, winzip etc do it I believe (this involves running code to determine what the context menu items will be dependent on the file chosen).

The simple way, for simple functionality, is you can add an entry in the registry :

HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command

Where <file type> is the files that this context menu should apply to i.e. *, .mdb, .doc

and

<display text> what you want to show in the context menu.

Then add the default string as a path to the application you want to launch from the context menu, and you can use %1 to refer to the currently selected file i.e. for MS Access I use :

HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"

This then adds a context menu item for any file I select (hence the *), which allows me to launch it in MS Access 2000.

Of course, always back up your registry before hacking it.

Your program could do this during install, or on first run.

like image 193
Jayden Avatar answered Oct 19 '22 22:10

Jayden


You could also package the java program in an installer like NSIS and you could use NSIS script to generate explorer context menu

like image 27
Harkish Avatar answered Oct 19 '22 23:10

Harkish