/** * Checks whether a registry key exists. * * @param root * HKEY_LOCAL_MACHINE, etc. * @param key * Path to the registry key. * @return True if the key exists. */ public static boolean registryKeyExists(HKEY root, String key) { return registryKeyExists(root, key, 0); }
private void checkPathDoesNotExist( String rootKey, String keyPath ) { if (Advapi32Util.registryKeyExists(getHKey(rootKey), keyPath)) { throw new RegistryOperationsException("Registry path already exists. " + getDescription(rootKey, keyPath, null)); } }
private static Set<String> findJavaHomesOnWindows(final String keyJavaHome, final String[] keys) { final Set<String> javaHomes = new HashSet<>(keys.length); for (final String key : keys) { if (Advapi32Util.registryKeyExists(HKEY_LOCAL_MACHINE, keyJavaHome + "\\" + key)) { final String javaHome = Advapi32Util.registryGetStringValue(HKEY_LOCAL_MACHINE, keyJavaHome + "\\" + key, "JavaHome"); if (StringUtils.isNoneBlank(javaHome)) { if (new File(javaHome).exists()) { javaHomes.add(javaHome); } } } } return javaHomes; }
private static void addAllJavaHomesOnWindows(final String keyJre, final Set<String> javaHomes) { if (Advapi32Util.registryKeyExists(HKEY_LOCAL_MACHINE, keyJre)) { javaHomes.addAll(findJavaHomesOnWindows(keyJre, Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, keyJre))); } }
/** * @param server The server for remote logging * @param source The Event View Source * @param application The Event View application (location) * @param eventMessageFile The message file location in the file system * @param categoryMessageFile The message file location in the file system * @return */ private HANDLE registerEventSource(String server, String source, String application, String eventMessageFile, String categoryMessageFile) { String applicationKeyPath = EVENT_LOG_PATH + application; String eventSourceKeyPath = applicationKeyPath + "\\" + source; if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, applicationKeyPath)) { if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath)) { setVariableKeys(eventMessageFile, categoryMessageFile, eventSourceKeyPath); } else { createAndSetAllKeys(eventMessageFile, categoryMessageFile, eventSourceKeyPath); } } else { createAndSetAllKeys(eventMessageFile, categoryMessageFile, eventSourceKeyPath); } HANDLE h = Advapi32.INSTANCE.RegisterEventSource(server, source); if (h == null) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return h; }