private String getVlcInstallDir() { try { return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, VLC_INSTALL_DIR_KEY); } catch(Exception e) { return null; } }
/** * Get names of the registry key's sub-keys. * * @param root * Root key. * @param keyPath * Path to a registry key. * @return Array of registry key names. */ public static String[] registryGetKeys(HKEY root, String keyPath) { return registryGetKeys(root, keyPath, 0); }
/** * Get a table of registry values. * * @param root * Registry root. * @param keyPath * Regitry key path. * @return Table of values. */ public static TreeMap<String, Object> registryGetValues(HKEY root, String keyPath) { return registryGetValues(root, keyPath, 0); }
/** * * @param eventMessageFile The message file location in the file system * @param categoryMessageFile The message file location in the file system * @param eventSourceKeyPath The registry path */ private void createAndSetAllKeys(String eventMessageFile, String categoryMessageFile, String eventSourceKeyPath) { if (Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath)) { Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "TypesSupported", TYPES_SUPPORTED); Advapi32Util.registrySetIntValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, "CategoryCount", CATEGORY_COUNT); setVariableKeys(eventMessageFile, categoryMessageFile, eventSourceKeyPath); } }
/** * Set the file location only if it does not exist or has changed. * * @param eventMessageFile The message file location in the file system * @param categoryMessageFile The message file location in the file system * @param eventSourceKeyPath The registry path */ private void setVariableKeys(String eventMessageFile, String categoryMessageFile, String eventSourceKeyPath) { if (!Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, EVENT_MESSAGE_FILE) || !Advapi32Util .registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, EVENT_MESSAGE_FILE) .equalsIgnoreCase(eventMessageFile)) { Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, EVENT_MESSAGE_FILE, eventMessageFile); } if (!Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, CATEGORY_MESSAGE_FILE) || !Advapi32Util .registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, CATEGORY_MESSAGE_FILE) .equalsIgnoreCase(categoryMessageFile)) { Advapi32Util.registrySetStringValue(WinReg.HKEY_LOCAL_MACHINE, eventSourceKeyPath, CATEGORY_MESSAGE_FILE, categoryMessageFile); } }
phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT, "CLSID", WinNT.KEY_ALL_ACCESS); InfoKey infoKey = Advapi32Util.registryQueryInfoKey(phkResult.getValue(), WinNT.KEY_ALL_ACCESS); EnumKey enumKey = Advapi32Util.registryRegEnumKey(phkResult.getValue(), i); subKey = Native.toString(enumKey.lpName); phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(), subKey, WinNT.KEY_ALL_ACCESS); InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(phkResult2.getValue(), WinNT.KEY_ALL_ACCESS); EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(phkResult2.getValue(), y); String subKey2 = Native.toString(enumKey2.lpName); comInfo.inprocHandler32 = (String)Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null); }else if(subKey2.equals("InprocServer32")) { comInfo.inprocServer32 = (String)Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null); }else if(subKey2.equals("LocalServer32")) { comInfo.localServer32 = (String)Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null); }else if(subKey2.equals("ProgID")) { comInfo.progID = (String)Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null); }else if(subKey2.equals("TypeLib")) { comInfo.typeLib = (String)Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, 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))); } }
/** * Retrieves a security identifier (SID) for the account on the current * system. * * @param accountName * Specifies the account name. * @return A structure containing the account SID; */ public static Account getAccountByName(String accountName) { return getAccountByName(null, accountName); }
/** * Gets the user groups. * * @return the user groups */ private Account[] getUserGroups() { if (this.userGroups == null) { this.userGroups = Advapi32Util.getTokenGroups(this.windowsIdentity); } return this.userGroups.clone(); }
/** * Create a registry key. * * @param hKey * Parent key. * @param keyName * Key name. * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY hKey, String keyName) { return registryCreateKey(hKey, keyName, 0); }
/** * Set a string value in registry. * * @param root * Root key. * @param keyPath * Path to an existing registry key. * @param name * Value name. * @param value * Value to write to registry. */ public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) { registrySetStringValue(root, keyPath, name, value, 0); }
/** * Set an integer value in registry. * * @param root * Root key. * @param keyPath * Path to an existing registry key. * @param name * Value name. * @param value * Value to write to registry. */ public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) { registrySetIntValue(root, keyPath, name, value, 0); }
/** * 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); }
tabProcGrowth = Advapi32Util.registryGetValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main", "TabProcGrowth").toString(); } catch (Win32Exception | NullPointerException e) { tabProcGrowth = "1";
phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT, "CLSID", WinNT.KEY_READ); InfoKey infoKey = Advapi32Util.registryQueryInfoKey( phkResult.getValue(), WinNT.KEY_READ); EnumKey enumKey = Advapi32Util.registryRegEnumKey( phkResult.getValue(), i); subKey = Native.toString(enumKey.lpName); phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(), subKey, WinNT.KEY_READ); InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey( phkResult2.getValue(), WinNT.KEY_READ); EnumKey enumKey2 = Advapi32Util.registryRegEnumKey( phkResult2.getValue(), y); String subKey2 = Native.toString(enumKey2.lpName); .registryGetValue(phkResult2.getValue(), subKey2, null); } else if (subKey2.equals("InprocServer32")) { comInfo.inprocServer32 = (String) Advapi32Util .registryGetValue(phkResult2.getValue(), subKey2, null); } else if (subKey2.equals("LocalServer32")) { comInfo.localServer32 = (String) Advapi32Util .registryGetValue(phkResult2.getValue(), subKey2, null);
/** * Windows Account. * * @param accountName * Username, without a domain or machine. * @param systemName * Machine name. */ public WindowsAccountImpl(final String accountName, final String systemName) { this(Advapi32Util.getAccountByName(systemName, accountName)); }
/** * Gets the user groups. * * @return the user groups */ private Account[] getUserGroups() { if (this.userGroups == null) { this.userGroups = Advapi32Util.getTokenGroups(this.windowsIdentity); } return this.userGroups.clone(); }
/** * Create a registry key. * * @param root * Root key. * @param parentPath * Path to an existing registry key. * @param keyName * Key name. * @return True if the key was created, false otherwise. */ public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { return registryCreateKey(root, parentPath, keyName, 0); }
/** * Applies a String(REG_SZ) value on the specified key. * * The key will be created if does not exist. * The key type will be changed if needed. * * @param keyPath * @param keyName * @param keyValue */ @Override public void setStringValue( String rootKey, String keyPath, String keyName, String keyValue ) { log.info("Set String value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName)); try { Advapi32Util.registrySetStringValue(getHKey(rootKey), keyPath, keyName, keyValue); } catch (RuntimeException re) { throw new RegistryOperationsException("Couldn't set registry String value '" + keyValue + "' to: " + getDescription(rootKey, keyPath, keyName), re); } }