From 58ba4e28e7b42535bfcd0df1b893880aa5b5d993 Mon Sep 17 00:00:00 2001 From: GhostFlying Date: Mon, 10 Nov 2014 12:48:30 +0800 Subject: [PATCH] enable proxy for all connections --- shadowsocks-csharp/Controller/SystemProxy.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/shadowsocks-csharp/Controller/SystemProxy.cs b/shadowsocks-csharp/Controller/SystemProxy.cs index 884c7260..a578752a 100755 --- a/shadowsocks-csharp/Controller/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/SystemProxy.cs @@ -35,6 +35,8 @@ namespace Shadowsocks.Controller registry.SetValue("ProxyServer", ""); registry.SetValue("AutoConfigURL", "http://127.0.0.1:8090/pac?t=" + GetTimestamp(DateTime.Now)); SystemProxy.NotifyIE(); + //Must Notify IE first, or the connections do not chanage + CopyProxySettingFromLan(); } catch (Exception) { @@ -54,6 +56,7 @@ namespace Shadowsocks.Controller registry.SetValue("ProxyServer", ""); registry.SetValue("AutoConfigURL", ""); SystemProxy.NotifyIE(); + CopyProxySettingFromLan(); } catch (Exception) { @@ -62,6 +65,25 @@ namespace Shadowsocks.Controller } } + private static void CopyProxySettingFromLan() + { + RegistryKey registry = + Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", + true); + var defulatValue = registry.GetValue("DefaultConnectionSettings"); + var connections = registry.GetValueNames(); + foreach (String each in connections){ + if (!(each.Equals("DefaultConnectionSettings") + || each.Equals("LAN Connection") + || each.Equals("SavedLegacySettings"))) + { + //set all the connections's proxy as the lan + registry.SetValue(each, defulatValue); + } + } + NotifyIE(); + } + private static String GetTimestamp(DateTime value) { return value.ToString("yyyyMMddHHmmssffff");