public static void EnableProxy() { #if !DEBUG //if(System.Environment.OSVersion.Version <= //if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) //{ // log.Info("Enabel Proxy Win7!"); // try { ProxyRoutines.SetProxy("http=127.0.0.1:8090"); } // catch (Exception exp) { log.Error(exp.ToString()); } //} //else { log.Info("Enabel Proxy!"); try { if (!GetProxy()) { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { TrollProxyHelper.SetHttpProxy("127.0.0.1", 8090); } else { SystemProxyHelper.SetHttpProxy("127.0.0.1", 8090); } FireFoxHelper.AddFirefox(); } } catch (Exception e) { log.Error(e.ToString()); } } #endif }
public static void DisableProxy() { //unset proxy again to make sure #if !DEBUG //if (System.Environment.OSVersion.Version.Major<=6 && System.Environment.OSVersion.Version.Minor<=1) //{ // log.Info("Disable Proxy Win7!"); // try // { // ProxyRoutines.SetProxy(false); // } // catch (Exception exp) // { log.Error(exp.ToString()); } //} //else { try { if (GetProxy()) { log.Info("Disable Proxy!"); //在关机时,不能refresh,否则会导致无法修改成功,其他时候则要刷新,否则会导致无法刷新 if (kCloseReason == CloseReason.WindowsShutDown) { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { log.Info("Win7 Disable proxy on Exit!"); TrollProxyHelper.RemoveHttpProxyWithRefresh(); } else { log.Info("Disable proxy without Refresh!"); SystemProxyHelper.DisableAllProxyWithourRestoreAndRefresh(); } //int tryTimes = 10; //while (tryTimes-- > 0) //{ //SystemProxyHelper.DisableAllProxyWithourRestore(); //reg.SetValue("ProxyEnable", 0); //reg.Flush(); ////read again //if ((int)reg.GetValue("ProxyEnable") != 0) // Thread.Sleep(50); ////else // //break; RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); log.Info("ProxyEnable Value: " + reg.GetValue("ProxyEnable")); //} } else { if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1) { log.Info("Win7 Disable proxy!"); TrollProxyHelper.RemoveHttpProxy(); } else { log.Info("Disable proxy with Refresh!"); SystemProxyHelper.DisableAllProxyWithourRestore(); } } FireFoxHelper.RemoveFirefox(); } } catch (Exception exp) { log.Error(exp.ToString()); } } #endif }