如何以编程方式更改 LAN 设置(代理配置)
我正在编写一个程序来根据我连接的网络自动切换我的代理地址。
到目前为止,除了我在下面突出显示的部分之外,我已经完成了所有工作。
有没有办法更改自动配置脚本和自动检测代码中的设置?
解决方案可以是 P/Invoke 注册表编辑。我只需要一些有用的东西。
I am writing a program to automatically switch my proxy address based on the network I am connected to.
I have so far got everything to work except the part that I have highlighted below.
Is there any way to change the automatic configuration script and the automatically detect settings in code?
The solution can be either P/Invoke registry editing. I just need something that works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用注册表更改代理设置。请参阅以下链接:
http://support.microsoft.com/kb/819961
键路径:
HKEY_CURRENT_USER\ Software\Microsoft\Windows\CurrentVersion\Internet Settings
值:
A SuperUser.com 中的问题 有关如何禁用 ie 代理配置中的自动检测设置。在 IE 代理配置中禁用“自动检测设置”
片段,取自 Internet Explorer 通过注册表自动配置脚本定义。
脚本 1: 这将启用 AutoConf 脚本并定义它是什么(将 http://xxxx 替换为您的脚本)
脚本 2:此脚本禁用 AutoConf 脚本并启用代理服务器(但有例外)。
You can change proxy settings by using the registry. See the following link:
http://support.microsoft.com/kb/819961
Key path:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
Values:
A question in SuperUser.com regarding how to disable automatically detect settings in ie proxy configuration. Disable "Automatically detect settings" in IE proxy configuration
A snippet, taken from Internet Explorer Automatic Configuration Script Definition via Registry.
Script 1: This enables the AutoConf Script and defines what it is (exchange the http://xxxx with your script)
Script 2: This script Disables the AutoConf Script and enables a proxy server with exceptions.
我彻底搜索了这个。但由于我找不到,我编写了以下适用于此目的的代码片段。
I searched all through for this. But as I couldnt find, I had written the below code snippete that works for this purpose.
我回答是因为我无权对答案发表评论。我想指出操作注册表与使用 InternetSetOptionAPI 之间的区别。如果您直接点击注册表来更改代理设置,则 Chrome 等依赖于 WinInet 代理配置的浏览器不会立即获取新设置,但如果您使用 InternetSetOptionAPI 进行更改,则将立即使用新设置。这是我的经验。我没有详细了解在操作注册表后可以做什么来获取设置。
编辑:
为了刷新 WinInet 代理设置,您可以执行 InternetSetOption API 的简单 PInvoke,如下所示
来源:在 C# 中以编程方式设置浏览器代理设置
I am answering because I am not allowed to comment on answers. I would like to point out a difference between manipulating registry vs using InternetSetOptionAPI. If you directly poke registry to change proxy settings then browsers like Chrome that depends on WinInet proxy configuration won't immediately pickup the new settings but if you change using InternetSetOptionAPI the new settings will be used immediately. This is my experience. I did not go into the details to find out what can be done to pickup the settings after manipulating the registry.
EDIT:
In order to refresh the WinInet proxy settings you can do a simple PInvoke of InternetSetOption API as follows
Source : Programmatically Set Browser Proxy Settings in C#
比 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。”
Better than http://support.microsoft.com/kb/819961, via .REG file, we should refer http://support.microsoft.com/kb/226473 "How to programmatically query and set proxy settings under Internet Explorer", use InternetSetOption().
As http://blogs.msdn.com/b/ieinternals/archive/2013/10/11/web-proxy-configuration-and-ie11-changes.aspx said: "Rather than attempting to “poke” the registry directly, the proper way to update the proxy setting is to use the InternetSetOption API."
您只需修改该值:
请参阅此链接。
You just need modify the value:
See this link.