tags:

views:

124

answers:

3

Is there a way to get the location of an installed application without searching through the file system?

EDIT: Sorry for not making the question clear enough, What i am trying to is like figure out where firefox is installed from within an java application. I would like to initiate an install for an extension.

+2  A: 

EDIT: Firefox has a registry key in HKLM\Software\Mozilla\Mozilla Firefox\\Main\InstallDirectory key. There is also a CurrentVersion key in that same HKLM\Software\Mozilla path that you can get the version number from.

Jeff Storey
A: 

On Linux you can use Runtime.exec() to call the which system program, eg which firefox would return something like /usr/bin/firefox. This won't work on Windows, and unfortunately doesn't appear to work on OS X either, despite it being UNIX-based.

jwaddell
for os x "open -a Firefox <filename>" works.
Hamza Yerlikaya
A: 

The only way to do this on Windows is via a registry read. Jeff Storey's post has the reg key you need. As for doing this from Java, my original response was going to be: you can't without using JNI.

But then I did some googling, and found this library

The approach is a bit novel b/c it involves accessing parts of Sun's implementation of the Preferences API that aren't generally available. This is, certainly, not going to be compatible for different JVMs, and could break as Sun's JRE evolves - but... well - I'll bet it would be useful for at least a couple of years, maybe longer. And it's a lot easier than writing the JNI yourself...

Kevin Day