/** * Go down the registry tree to find a key with the given name. * * @param root Root of the registry hive * @param name Name of the subkey to seach for * @return The matching subkey or null if not found */ public RegistryKey findKey(RegistryKey root, String name) { RegistryKey currentKey = root; // Split the key name into parts String[] parts = name.split("\\\\"); for (String part : parts) { if (part.length() > 0) { try { currentKey = currentKey.getSubkey(part); } catch (Exception ex) { // We get an exception if the value wasn't found (not a RegistryParseException). // There doesn't seem to be a cleaner way to test for existance without cycling though // everything ourselves. (Broad catch because things other than RegistryParseException // can happen) return null; } } } // If we make it this far, we've found it return currentKey; }