How can I check with Java if a program is installed on a Windows system, for example to check for Mozilla Firefox?
2 Answers
I assume that you're talking about Windows. As Java is intented to be a platform independent language and the way how to determine it differs per platform, there's no standard Java API to check that. You can however do it with help of JNI calls on a DLL which crawls the Windows registry. You can then just check if the registry key associated with the software is present in the registry. There's a 3rd party Java API with which you can crawl the Windows registry: jRegistryKey.
Here's an SSCCE with help of jRegistryKey:
package com.stackoverflow.q2439984;
import java.io.File;
import java.util.Iterator;
import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RootKey;
public class Test {
public static void main(String... args) throws Exception {
RegistryKey.initialize(Test.class.getResource("jRegistryKey.dll").getFile());
RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\Mozilla");
for (Iterator<RegistryKey> subkeys = key.subkeys(); subkeys.hasNext();) {
RegistryKey subkey = subkeys.next();
System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox".
}
}
}
If you however intend to have a platformindependent application, then you'll also have to take into account the Linux/UNIX/Mac/Solaris/etc (in other words: anywhere where Java is able to run) ways to detect whether FF is installed. Else you'll have to distribute it as a Windows-only application and do a System#exit()
along with a warning whenever System.getProperty("os.name")
does not Windows.
Sorry, I don't know how to detect in other platforms whether FF is installed or not, so don't expect an answer from me for that ;)

- 1,082,665
- 372
- 3,610
- 3,555
-
1+1 for introducing jRegistryKey, thanks – stacker Mar 13 '10 at 23:40
-
the registry is not always cleared when an application is uninstalled. – ecstrema Feb 11 '19 at 03:05
There's no API I know of that will allow you to do this - I expect the most general method is to check file locations.
Other approaches (like checking Windows registry) are OS-dependent.

- 42,504
- 27
- 146
- 186