/** * 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); }
/** * @return an array containing the serial ports, taken from registry HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM * @throws Exception in case something goes wrong with the registry */ private String[] windowsGetSerialPortsFromRegistry() throws Exception { final TreeMap<String, Object> map = com.sun.jna.platform.win32.Advapi32Util.registryGetValues(com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM"); final List<String> ports = new ArrayList<String>(map.size()); for (Object p : map.values()) { if (p != null && p.toString().startsWith("COM")) ports.add(p.toString()); } return ports.toArray(new String[0]); }
/** * @return an array containing the serial ports, taken from registry HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM * @throws Exception in case something goes wrong with the registry */ private String[] windowsGetSerialPortsFromRegistry() throws Exception { final TreeMap<String, Object> map = com.sun.jna.platform.win32.Advapi32Util.registryGetValues(com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM"); final List<String> ports = new ArrayList<String>(map.size()); for (Object p : map.values()) { if (p != null && p.toString().startsWith("COM")) ports.add(p.toString()); } return ports.toArray(new String[0]); }
private static TreeMap<String, Object> visualStudioVS7SxS(com.sun.jna.platform.win32.WinReg.HKEY root, String key) { com.sun.jna.platform.win32.WinReg.HKEYByReference phkKey = new com.sun.jna.platform.win32.WinReg.HKEYByReference(); int rc = com.sun.jna.platform.win32.Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, com.sun.jna.platform.win32.WinNT.KEY_READ | com.sun.jna.platform.win32.WinNT.KEY_WOW64_32KEY, phkKey); if (rc != com.sun.jna.platform.win32.W32Errors.ERROR_SUCCESS) { throw new com.sun.jna.platform.win32.Win32Exception(rc); } try { return com.sun.jna.platform.win32.Advapi32Util.registryGetValues(phkKey.getValue()); } finally { rc = com.sun.jna.platform.win32.Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); if (rc != com.sun.jna.platform.win32.W32Errors.ERROR_SUCCESS) { throw new com.sun.jna.platform.win32.Win32Exception(rc); } } }
/** * 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) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } try { return registryGetValues(phkKey.getValue()); } finally { rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } } }
/** * Get a table of registry values. * * @param root * Registry root. * @param keyPath * Regitry key path. * @param samDesiredExtra * Registry key security and access rights to be requested in addition to WinNT.KEY_READ. * (e.g WinNT.KEY_WOW64_32KEY or WinNT.KEY_WOW64_64KEY to force 32bit or 64bit registry access.) * @return Table of values. */ public static TreeMap<String, Object> registryGetValues(HKEY root, String keyPath, int samDesiredExtra) { HKEYByReference phkKey = new HKEYByReference(); int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | samDesiredExtra, phkKey); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } try { return registryGetValues(phkKey.getValue()); } finally { rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc); } } }