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); + } } }