Java Code Examples for com.sun.jna.platform.win32.WinReg#HKEY
The following examples show how to use
com.sun.jna.platform.win32.WinReg#HKEY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalRegistryOperations.java From ats-framework with Apache License 2.0 | 6 votes |
private void checkKeyExists( String rootKey, String keyPath, String keyName ) { try { WinReg.HKEY rootHKey = getHKey(rootKey); if (!Advapi32Util.registryValueExists(rootHKey, keyPath, keyName)) { throw new RegistryOperationsException("Registry key does not exist. " + getDescription(rootKey, keyPath, keyName)); } } catch (Win32Exception e) { throw new RegistryOperationsException("Registry key path does not exist. " + getDescription(rootKey, keyPath, keyName), e); } }
Example 2
Source File: LocalRegistryOperations.java From ats-framework with Apache License 2.0 | 6 votes |
private WinReg.HKEY getHKey( String key ) { if (key.equalsIgnoreCase(HKEY_CLASSES_ROOT)) { return WinReg.HKEY_CLASSES_ROOT; } else if (key.equalsIgnoreCase(HKEY_CURRENT_USER)) { return WinReg.HKEY_CURRENT_USER; } else if (key.equalsIgnoreCase(HKEY_LOCAL_MACHINE)) { return WinReg.HKEY_LOCAL_MACHINE; } else if (key.equalsIgnoreCase(HKEY_USERS)) { return WinReg.HKEY_USERS; } else if (key.equalsIgnoreCase(HKEY_CURRENT_CONFIG)) { return WinReg.HKEY_CURRENT_CONFIG; } else { throw new RegistryOperationsException("Unsupported root key '" + key + "'"); } }
Example 3
Source File: Options.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Returns the osu! installation directory. * @return the directory, or null if not found */ private static File getOsuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) return null; // only works on Windows // registry location final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue); } catch (Win32Exception e) { return null; // key/value not found } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) return null; File dir = new File(m.group(1)); return (dir.isDirectory()) ? dir : null; }
Example 4
Source File: ContextMenuTools.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
public static boolean isAddedToContextMenu() { if (!Platform.isWindows()) { return false; } final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE; final String REG_CLASSES_PATH = "Software\\Classes\\"; try { if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf")) { return false; } String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf", ""); if (clsName == null) { return false; } return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + clsName + "\\shell\\ffdec"); } catch (Win32Exception ex) { return false; } }
Example 5
Source File: Configuration.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
private File loadOsuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) { return null; } final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue); } catch (Win32Exception ignored) { return null; } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) { return null; } File dir = new File(m.group(1)); if (dir.isDirectory()) { return dir; } return null; }
Example 6
Source File: JnaWinRegistry.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Nullable public static String readString(WinReg.HKEY hkey, String key, String valueName) { if (! isAvailable()) { return null; } try { return Advapi32Util.registryGetStringValue(hkey, key, valueName); } catch (Win32Exception e) { return null; } }
Example 7
Source File: ContextMenuTools.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
private static void registryDeleteKey(WinReg.HKEY hKey, String keyName) { boolean exists = Advapi32Util.registryKeyExists(hKey, keyName); if (exists) { Advapi32Util.registryDeleteKey(hKey, keyName); } }
Example 8
Source File: ContextMenuTools.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
private static void registryDeleteValue(WinReg.HKEY root, String keyPath, String valueName) { boolean exists = Advapi32Util.registryValueExists(root, keyPath, valueName); if (exists) { Advapi32Util.registryDeleteValue(root, keyPath, valueName); } }