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
          主站蜘蛛池模板: 石渠县| 临洮县| 木兰县| 大城县| 高邮市| 日照市| 商都县| 金门县| 耒阳市| 萨迦县| 桂林市| 白水县| 扎兰屯市| 金门县| 塔河县| 彭泽县| 洛宁县| 营口市| 屯留县| 襄垣县| 仁怀市| 油尖旺区| 抚宁县| 宜州市| 云梦县| 柏乡县| 鱼台县| 闵行区| 河间市| 鹰潭市| 龙胜| 上栗县| 泸水县| 娱乐| 林口县| 淮北市| 西华县| 白玉县| 西宁市| 望谟县| 萨迦县|