How can I read these DWORD values from the Windows registry using java.util.prefs.Preferences. I can read data of type REG_SZ, but when reading type REG_DWORD it returns null.
Preferences userRoot = Preferences.userRoot();
Class clz = userRoot.getClass();
openKey = clz.getDeclaredMethod("openKey", byte[].class, int.class, int.class);
openKey.setAccessible(true);
final Method closeKey = clz.getDeclaredMethod("closeKey", int.class);
closeKey.setAccessible(true);
byte[] valb = null;
String key = null;
Integer handle = -1;
final Method winRegQueryValue = clz.getDeclaredMethod("WindowsRegQueryValueEx", int.class, byte[].class);
winRegQueryValue.setAccessible(true);
key = "Software\\SimonTatham\\PuTTY\\Sessions\\myMachine";
handle = (Integer) openKey.invoke(userRoot, toCstr(key), KEY_READ, KEY_READ);
valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(), toCstr("HostName"));
valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(), toCstr("PortNumber"));
closeKey.invoke(Preferences.userRoot(), handle);
Any idea?
source
share