9910

单飞

   :: 首页 :: 联系 :: 聚合  :: 管理
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;
    }
posted on 2009-07-08 13:27 单飞 阅读(241) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: