public static String ReadRegistry(String path, String name) { try { Registry reg = new Registry(); RegistryKey key = null; if (path.startsWith("HKEY_LOCAL_MACHINE\\")) { path = path.replace("HKEY_LOCAL_MACHINE\\", ""); key = reg.openSubkey(reg.HKEY_LOCAL_MACHINE, path, RegistryKey.ACCESS_ALL); } else if (path.startsWith("HKEY_LOCAL_MACHINE\\")) { path = path.replace("HKEY_CURRENT_USER\\", ""); key = reg.openSubkey(reg.HKEY_CURRENT_USER, path, RegistryKey.ACCESS_ALL); } // = new RegStringValue(key,value,RegistryValue.REG_SZ); RegistryValue keyvalue = key.getValue(name); return new String(keyvalue.getByteData()); // String.valueOf(); } catch (Exception ex) { // ex.printStackTrace(); return ""; } // String value = null; // try { // at.jta.Regor reg = new at.jta.Regor(); // at.jta.Key key = new at.jta.Key(); // key.setPath(path); // if (key._isValidKey()) { // value = reg.readAnyValueString(key, name); // } // } catch (Exception ex) { // ex.printStackTrace(); // } // if (value == null) { // return ""; // // } // return (value); }
public static void WriteRegistry(String path, String name, String value) { try { Registry reg = new Registry(); RegistryKey key = null; if (path.startsWith("HKEY_LOCAL_MACHINE\\")) { path = path.replace("HKEY_LOCAL_MACHINE\\", ""); key = reg.openSubkey(reg.HKEY_LOCAL_MACHINE, path, RegistryKey.ACCESS_ALL); } else if (path.startsWith("HKEY_LOCAL_MACHINE\\")) { path = path.replace("HKEY_CURRENT_USER\\", ""); key = reg.openSubkey(reg.HKEY_CURRENT_USER, path, RegistryKey.ACCESS_ALL); } RegStringValue keyvalue = new RegStringValue(key, name, RegistryValue.REG_SZ); keyvalue.setData(value); key.setValue(keyvalue); } catch (Exception ex) { ex.printStackTrace(); } }