/ Published in: Java
A paste from a blog (http://lenkite.blogspot.com/2008/05/access-windows-registry-using-java.html) entry which demonstrates how to access windows registry in Java.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.lang.reflect.Method; import java.util.prefs.Preferences; public class JavaRegistryHack { private static final int HKEY_CURRENT_USER = 0x80000001; private static final int KEY_QUERY_VALUE = 1; private static final int KEY_SET_VALUE = 2; private static final int KEY_READ = 0x20019; final Preferences userRoot = Preferences.userRoot(); final Preferences systemRoot = Preferences.systemRoot(); final Class clz = userRoot.getClass(); try { byte[].class, int.class, int.class); openKey.setAccessible(true); int.class); closeKey.setAccessible(true); "WindowsRegQueryValueEx", int.class, byte[].class); winRegQueryValue.setAccessible(true); "WindowsRegEnumValue1", int.class, int.class, int.class); winRegEnumValue.setAccessible(true); "WindowsRegQueryInfoKey1", int.class); winRegQueryInfo.setAccessible(true); byte[] valb = null; //Query Internet Settings for Proxy key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; valb = (byte[]) winRegQueryValue.invoke(userRoot, handle.intValue(), toCstr("ProxyServer")); closeKey.invoke(Preferences.userRoot(), handle); // Query for IE version key = "SOFTWARE\\Microsoft\\Internet Explorer"; valb = (byte[]) winRegQueryValue.invoke(systemRoot, handle, toCstr("Version")); closeKey.invoke(Preferences.systemRoot(), handle); e.printStackTrace(); } } byte[] result = new byte[str.length() + 1]; for (int i = 0; i < str.length(); i++) { result[i] = (byte) str.charAt(i); } result[str.length()] = 0; return result; }