http://www.trustice.com/java/jnireg/index.shtml registry-3.1.3.zip
public static void setProxy(String ip, int port) {
String topKeyName = "HKCU";
String keyName = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
RegistryKey topKey = Registry.getTopLevelKey(topKeyName);
RegistryUtil.setDWordCommand(topKey, keyName, "ProxyEnable", "1");
RegistryUtil.setStringCommand(topKey, keyName, "ProxyServer", ip + ":" + port);
}
public static boolean isProxy() {
try {
RegistryKey registryKey = Registry.openSubkey(Registry.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", RegistryKey.ACCESS_READ);
RegistryValue registryValue = registryKey.getValue("ProxyEnable");
boolean proxyEnable = ((RegDWordValue) registryValue).getData() != 0;
System.out.println("IE 是否启用了代理设置: " + proxyEnable);
if (proxyEnable) {
registryValue = registryKey.getValue("ProxyServer");
System.out.println("IE 代理服务器是: " + new String(registryValue.getByteData()));
return true;
}
} catch (NoSuchKeyException ne) {
ne.printStackTrace();
} catch (RegistryException re) {
re.printStackTrace();
}
return false;
}
|