How to check if a program is installed on Windows system [duplicate]

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 😉

Leave a Comment