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 單飛 閱讀(265) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 句容市| 安泽县| 阿巴嘎旗| 秦安县| 邵武市| 大余县| 来宾市| 双江| 科技| 皮山县| 庆阳市| 河曲县| 军事| 本溪市| 洛宁县| 建德市| 页游| 贡嘎县| 广饶县| 宣城市| 元朗区| 汝阳县| 忻州市| 蓝山县| 康平县| 沙雅县| 永嘉县| 睢宁县| 威信县| 保德县| 沾化县| 锦屏县| 逊克县| 建始县| 门源| 山阴县| 锦州市| 辽阳县| 洞头县| 金湖县| 龙井市|