我正在写一个程序来自动切换我的代理地址基于我连接的networking。
到目前为止,除了我在下面强调的部分之外,我已经做了所有的工作。
有没有办法改变自动configuration脚本,并自动检测代码中的设置?
networking启动命令延迟?
Windows – 将键盘键映射到与鼠标左键相同的操作
强制Windows在closures时等待服务停止
特定networking接口IPv4可用性 – 无连接,本地,Internet
解决scheme可以是P / Invokeregistry编辑。 我只需要一些工作。
在.NET中使用NTFS压缩来压缩文件夹
奇怪的线程NullReferenceException当读取存在的值?
我如何才能知道给线程的实际时间片?
http://support.microsoft.com/kb/819961
关键路径: HKEY_CURRENT_USERSoftwareMicrosoftwindowsCurrentVersionInternet Settings
价值观:
"MigrateProxy"=dword:00000001 "ProxyEnable"=dword:00000001 "ProxyHttp1.1"=dword:00000000 "Proxyserver"="http://Proxyservername:80" "ProxyOverride"="<local>"
SuperUser.com中有关如何禁用自动检测ie代理配置中的设置的问题。 在IE代理配置中禁用“自动检测设置”
从Internet Explorer自动配置脚本定义通过注册表中摘取的代码片段。
脚本1:这将启用AutoConf脚本并定义它是什么(与您的脚本交换http:// xxxx )
Windows注册表编辑器版本5.00
[HKEY_CURRENT_USER Software Microsoft Windows CurrentVersion Internet Settings]
“AutoConfigURL”= “HTTP://xxx.xxx.xxx.xxx.xxxx”
“ProxyEnable”= DWORD:00000000
脚本2:此脚本禁用AutoConf脚本并启用具有例外的代理服务器。
Windows注册表编辑器版本5.00
[HKEY_CURRENT_USER Software Microsoft Windows CurrentVersion Internet Settings]
“ProxyEnable”= DWORD:00000001
“ProxyOverride”=“proxyexceptionname:端口号; anotherexceptionname:端口
“访问代理服务器”=“的ftp = MyFTPProxy:端口; HTTP = MYHTTPPROXY:PORT; HTTPS = MYHTTPSPROXY:PORT
“AutoConfigURL”= “”
我全部搜索了这个。 但是,正如我找不到,我已经写了下面的代码片段,为此目的。
/// <summary> /// Checks or unchecks the IE Options Connection setting of "Automatically detect Proxy" /// </summary> /// <param name="set">Provide 'true' if you want to check the 'Automatically detect Proxy' check Box. To uncheck,pass 'false'</param> public void IEAutoDetectProxy(bool set) { // Setting Proxy @R_59_4045@ion for IE Settings. RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections",true); byte[] defConnection = (byte[])RegKey.GetValue("DefaultConnectionSettings"); byte[] savedLegacySetting = (byte[])RegKey.GetValue("SavedLegacySettings"); if (set) { defConnection[8] = Convert.ToByte(9); savedLegacySetting[8] = Convert.ToByte(9); } else { defConnection[8] = Convert.ToByte(1); savedLegacySetting[8] = Convert.ToByte(1); } RegKey.SetValue("DefaultConnectionSettings",defConnection); RegKey.SetValue("SavedLegacySettings",savedLegacySetting); }
比http://support.microsoft.com/kb/819961好 ,通过.REG文件,我们应该参考http://support.microsoft.com/kb/226473 “ 如何以编程方式查询和设置Internet Explorer下的代理设置 ” ,使用InternetSetoption()。
正如http://blogs.msdn.com/b/ieinternals/archive/2013/10/11/web-proxy-configuration-and-ie11-changes.aspx所说:“与其试图直接”戳“注册表,更新代理设置的正确方法是使用InternetSetoption API。“
我正在回答,因为我不允许评论答案。 我想指出操作注册表与使用InternetSetoptionAPI之间的区别。 如果您直接使用注册表来更改代理设置,那么浏览器(如依赖于WinInet代理配置的Chrome)将不会立即获取新设置,但如果使用InternetSetoptionAPI更改,则会立即使用新设置。 这是我的经验。 我没有深入细节,找出在操作注册表之后可以采取什么操作。
编辑:为了刷新WinInet代理设置,你可以做一个简单的PInvoke的InternetSetoption API如下
internal class InternetSetoptionApi { [DllImport("wininet.dll")] public static extern bool InternetSetoption(IntPtr hInternet,int dwOption,IntPtr lpBuffer,int dwBufferLength); public const int INTERNET_OPTION_SETTINGS_CHANGED = 39; public const int INTERNET_OPTION_REFRESH = 37; public static void RefreshWinInetProxySettings() { // These lines implement the Interface in the beginning of program // They cause the OS to refresh the settings,causing IP to realy update InternetSetoption(IntPtr.Zero,INTERNET_OPTION_SETTINGS_CHANGED,IntPtr.Zero,0); InternetSetoption(IntPtr.Zero,INTERNET_OPTION_REFRESH,0); } }
来源: 编程设置浏览器代理设置在C#
你只需要修改这个值:
Registry Key : HKCUSoftwareMicrosoftwindowsCurrentVersionInternet Settings DWORD AutoDetect = 0 or 1
看到这个链接 。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。