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.
You just need modify the value:
See this link.
I searched all through for this. But as I couldnt find, I had written the below code snippete that works for this purpose.
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#
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.
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."