From 0f748bd933170cc2c118bab518167a10c19e8412 Mon Sep 17 00:00:00 2001 From: li3shiyi Date: Fri, 7 Aug 2015 15:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E7=94=A8=E7=B3=BB=E7=BB=9F=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=97=B6=E7=A6=81=E7=94=A8=E2=80=9C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E8=AE=BE=E7=BD=AE=E2=80=9D=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E6=97=A0=E5=BF=85=E8=A6=81=E6=97=B6=E4=B8=8D=E6=B8=85?= =?UTF-8?q?=E9=99=A4=E5=8E=9F=E6=9C=89=E4=BB=A3=E7=90=86=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E8=AE=BE=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/System/SystemProxy.cs | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/SystemProxy.cs b/shadowsocks-csharp/Controller/System/SystemProxy.cs index 5fe8a244..3bdb737f 100644 --- a/shadowsocks-csharp/Controller/System/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/System/SystemProxy.cs @@ -55,16 +55,21 @@ namespace Shadowsocks.Controller else pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now); registry.SetValue("ProxyEnable", 0); - registry.SetValue("ProxyServer", ""); + //registry.SetValue("ProxyServer", ""); //Unnecessary registry.SetValue("AutoConfigURL", pacUrl); } } else { registry.SetValue("ProxyEnable", 0); - registry.SetValue("ProxyServer", ""); + if (global) + { + registry.SetValue("ProxyServer", ""); + } registry.SetValue("AutoConfigURL", ""); } + //Set AutoDetectProxy Off + IEAutoDetectProxy(false); SystemProxy.NotifyIE(); //Must Notify IE first, or the connections do not chanage CopyProxySettingFromLan(); @@ -106,5 +111,30 @@ namespace Shadowsocks.Controller { return value.ToString("yyyyMMddHHmmssffff"); } + + /// + /// Checks or unchecks the IE Options Connection setting of "Automatically detect Proxy" + /// + /// Provide 'true' if you want to check the 'Automatically detect Proxy' check box. To uncheck, pass 'false' + private static void IEAutoDetectProxy(bool set) + { + RegistryKey registry = + Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", + true); + byte[] defConnection = (byte[])registry.GetValue("DefaultConnectionSettings"); + byte[] savedLegacySetting = (byte[])registry.GetValue("SavedLegacySettings"); + if (set) + { + defConnection[8] = Convert.ToByte(defConnection[8] & 8); + savedLegacySetting[8] = Convert.ToByte(savedLegacySetting[8] & 8); + } + else + { + defConnection[8] = Convert.ToByte(defConnection[8] & ~8); + savedLegacySetting[8] = Convert.ToByte(savedLegacySetting[8] & ~8); + } + registry.SetValue("DefaultConnectionSettings", defConnection); + registry.SetValue("SavedLegacySettings", savedLegacySetting); + } } }