I am trying to turn off the “Automatically Detect settings” in the proxy settings in Internet Explorer (IE), using vbscript (vbs).
It is not as easy as you would think. There are loads of forums out there where people are trying to find the answer. I now have working code, for my version of IE in my environment and whilst you need to do your own testing (not on production machines) I want to let the world know how I did it.
The problem is that this tick box is set by the following registry keys
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings
The value is binary and whilst reading this with vbs is easy, changing the huge Hex value into something you can save back, is almost impossible. The REG_BINARY in the Regwrite method wants an integer.
The value looks something like this (This has been edited to keep details private).
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
“DefaultConnectionSettings”=hex:46,00,00,00,67,38,00,00,03,00,00,00,10,00,00,\
73,74,72,61,2e,63,6f,6d,3b,2a,2e,6a,68,67,2e,6c,6f,63,61,6c,3b,31,39,32,2e,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
73,74,72,61,2e,63,6f,6d,3b,2a,2e,6a,68,67,2e,6c,6f,63,61,6c,3b,31,39,32,2e,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
64,61,74,a2,2c,55,62,09,d5,ce,01,00,00,00,00,00,00,00,00,00,00,00,00,01,00,\
00,00,02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00
“SavedLegacySettings”=hex:46,00,00,00,d1,4f,00,00,03,00,00,00,10,00,00,00,31,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
2e,74,65,6c,73,74,72,61,2e,63,6f,6d,3b,2a,2e,74,69,70,74,2e,74,65,6c,73,74,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
38,2e,32,2e,2a,3b,3c,6c,6f,63,61,6c,3e,00,00,00,00,01,00,00,00,1a,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
74,a2,2c,55,62,09,d5,ce,01,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,\
02,00,00,00,c0,a8,02,45,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00
I spent ages reading how the individual offsets changed certain details. I tried to work out how to change certain parts of these values. I also tried to work out how to reset these values back to a default settings.
Lot’s of people are arguing online what each value does. I got to the point where that was all meaningless.
I looked at importing a reg file to solve my problem. Then I had a change of thought. What if I could somehow force something into this key that blanks all settings but the one I want, and then trough code, add back the other values I needed.
If i can find the code I need and if IE rebuilds the rest of the key, this might be possible. I deleted the whole key. Went into IE and unticked just the “Automatically Detect settings” setting.
I then reviewed the registry and noted that the value of that key was now very simple. It was basically “0F” and the rest of the data was made up of “00”. So, I wrote my vbs code to delete the key, put back “0F” and then wrote the remainder of what I needed into the settings and … it works !
WSHShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”
WSHShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”,&H46,”REG_BINARY”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”,&H46,”REG_BINARY”
The rest of the code was
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”, 1, “REG_DWORD”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer”, Proxy IP
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride”, “IP addresses or servernanes here;<local>”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\DisablePasswordCaching”, 1, “REG_DWORD”
‘WSHShell.RegWrite “HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel\Autoconfig”, 0, “REG_DWORD”
This now leaves me with “Automatically Detect settings” off, “Use Automatic configuration script” off, “Bypass Proxy for local servers” on, Proxy details all filled in and a bypass list created.
Perfect !
#1 by vince on February 12, 2014 - 11:35 pm
Quote
Now that was bloody helpful, mate! It’s just as you stated: “There are loads of forums out there where people are trying to find the answer” and I used to be one of those people. Well, not anymore! Thanks!
#2 by Andy on March 13, 2014 - 1:47 am
Quote
Thank you – it works perfectly! I’ve no idea why Microsoft made it so hard to set this flag. Even setting it via GPO is hit-and-miss.
#3 by Ola on April 7, 2014 - 11:27 pm
Quote
Perfect, it works, thanks
#4 by John T. on April 19, 2014 - 10:17 am
Quote
MickyJ, thanks so much for posting this. I was trying to enforce some important proxy settings that were getting overridden by some mistakes that got into the default profile. To make a long story short, using your idea in my script was the only way to fix it without re-deploying dozens of PCs all over our area. Thanks for sharing this info.
#5 by mickyj on May 6, 2014 - 10:21 am
Quote
My Pleasure, I hate taking ages to find a solution and I know others do as well. If I can help anyone then I will 🙂
#6 by Eric on May 23, 2014 - 12:51 pm
Quote
Hi, when I run the script, I got “invalid root in registry key” in “HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel\Autoconfig”. Any idea what’s wrong with my script? (WIN7/IE8)
#7 by mickyj on May 27, 2014 - 5:07 pm
Quote
It looks to me that either you do not have administrative rights to that key or it is set and changed to some other setting by an enforced group policy.
Can you find that location in the registry? Can you add another key and delete the key you created ?
You can try saving the vbs file to the desktop and “right click, run as administrator”
#8 by Mohan on July 17, 2014 - 5:24 pm
Quote
Hi Micky..The proxy settings are changing fine for turning off…but for turning on it will take effect only after manually going into the proxy settings screen and press OK/CANCEL button. Can you please help me out for this…
#9 by mickyj on July 21, 2014 - 9:09 am
Quote
I will take a look as soon as I can …
#10 by mickyj on November 7, 2014 - 10:43 am
Quote
sorry, your comment got lost in amongst all the other replies to my blog. Is this still an issue ?
#11 by Mohan on July 17, 2014 - 5:32 pm
Quote
This is the Script I am using…
Option Explicit
dim oShell
set oShell = Wscript.CreateObject(“Wscript.Shell”)
oShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”
oShell.Regdelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”
oShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”,&H46,”REG_BINARY”
oShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”,&H46,”REG_BINARY”
if msgbox(“Turn Proxy on?”, vbQuestion or vbYesNo) = vbYes then
oShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer”, “proxy:8080”, “REG_SZ”
oShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”, 1, “REG_DWORD”
else
oShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”, 0, “REG_DWORD”
end if
Set oShell = Nothing
#12 by Harshil on July 23, 2014 - 1:43 am
Quote
Does this effect/harm the OS functionality ?Any chances of vulnerability or attacks over the internet ?
#13 by mickyj on August 8, 2014 - 8:48 am
Quote
Hello,
I can’t get an answer on this and honestly this is just a “hack” as there is no supported solution. It would be a “use at your own risk” kind of thing. I can say that once you modify the registry and then open IE for the first time, all registry entries then appear the same as any other PC so the window of time where you might be in danger is very small.
#14 by Jordan on September 6, 2014 - 1:37 am
Quote
This script works amazingly, but having never used wsh or windows scripting I had to learn a few things, and for anyone else wondering, I’ve included a working script below (you have to modify the proxy_ip and exception list to suit your needs). The first line creates the new shell object. The second line tells the script to ignore errors.
@Mickyj, I added an extra line and removed your other one for the Auto Config URL. RegDelete on \AutoConfigURL works great. WSHShell.RegWrite “HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel\Autoconfig”, 0, “REG_DWORD” was throwing an error.
Working Example:
Set WSHShell = CreateObject( “WScript.Shell” )
On Error Resume Next
WSHShell.RegDelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”
WSHShell.RegDelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”
WSHShell.RegDelete “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\AutoConfigURL”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings”, &H46, “REG_BINARY”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\SavedLegacySettings”, &H46, “REG_BINARY”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”, 1, “REG_DWORD”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer”, “PROXY_IP:PORT”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride”, “exception1.list.com;exception2.list.com;”
WSHShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\DisablePasswordCaching”, 1, “REG_DWORD”
Set WSHShell = Nothing
#15 by mickyj on September 6, 2014 - 10:29 am
Quote
Awesome !
#16 by frank vandebergh on September 9, 2014 - 3:52 pm
Quote
There is another way to change the automatically detect settings checkbox. It can be controlled using a registry key AutoDetect=0 or 1. Check my blog article for more information: http://blog.raido.be/?p=426
#17 by Merle Williams on December 4, 2014 - 1:09 am
Quote
Micky,
Thanks for this! I had narrows the setting down to this same section of hex, but didn’t yet have an elegant solution to modify it through code/registry.
As Mohan said (and never replied in the thread again): “…will take effect only after manually going into the proxy settings screen and press OK/CANCEL button. Can you please help me out for this…”
I’m mostly interested in getting Windows and IE to recognize toggling of ProxyEnable through code, but I imagine they’re affected through the same mechanisms. I’m using Procmon and Spy++, but with no luck yet. I’d truly appreciate your help on this one.
Thanks!
#18 by mickyj on December 8, 2014 - 3:37 pm
Quote
Hmm, I have a site with 350 PC’s and placed this code in their logon script. It has worked for all and we did not have to open the IE settings and press ok/cancel.
Are there any special group policies you are deploying? Wpad?
I will go and have another play.
Unfortunatly there are loads of poeple trying to make these settings work the way they want and to enable the bits they want and Microsoft do not allow a mechanism which is why my code is so brute force.
#19 by DaRattMan on December 9, 2014 - 4:23 am
Quote
I believe this is one of the settings that gets loaded by explorer.exe. During logon it should work, but at the desktop you need to refresh explorer… if you kill explorer.exe and start process explorer.exe does it work? If so, you need to broadcast the WM_SETTINGCHANGE message, which tells explorer to refresh… there are powershell scripts for this, but I’m not sure about VB
#20 by Liz Byrne on July 3, 2015 - 6:41 pm
Quote
No access to computer settings – blocked by viruses code 28 HKCU