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 !