How can I read DWORD value data from windows registry using java.util.prefs.Preferences. I can read REG_SZ type data but when reading REG_DWORD type, null is returned.
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);
//this line returns byte[] correctly
valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(), toCstr("HostName"));
//but this line returns null instead of byte[] even though there is a value of type REG_DWORD
valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(), toCstr("PortNumber"));
closeKey.invoke(Preferences.userRoot(), handle);
Any idea?