21

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?

Thilo
  • 257,207
  • 101
  • 511
  • 656

2 Answers2

18

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.

Jayden
  • 2,656
  • 2
  • 26
  • 31
  • That seems simple enough, thanks. Does this method also support grouping multiple entries into a submenu? – Thilo Dec 16 '08 at 00:10
  • How does one write a windows shell extension to do this? – Tom Dec 30 '10 at 12:41
  • 3
    How does one add such registry entry for folders and for all files (*.*)? – Tom Dec 30 '10 at 12:51
  • @Tom you might like checking this out http://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens – fernandohur Apr 11 '12 at 02:35
  • 2
    @Jayden In my JAVA program, how do I determine which file is being opened with this application? – Jisan Mahmud Sep 11 '12 at 09:56
  • Is possible to make a file type exception (I mean - use it for all files except of *.zip for example)? – Quark Aug 18 '16 at 13:03
4

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

Harkish
  • 2,262
  • 3
  • 22
  • 31