If you’re a mobile user who works both in and out of the office, then you may find yourself having to constantly ‘tweak’ your IE proxy settings all the time, and although it’s only a few mouse clicks, a few is always too many in my eyes.

The VBScript below will check for any currently open instances of Internet Explorer, prompt to kill them and then set the proxy settings for you.

All the proxy settings are contained in the Windows registry so are quite straight forward to maintain.

On Error Resume next  Const HKCU=&H80000001 'HKEY_CURRENT_USER  Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE    Const REG_SZ=1  Const REG_EXPAND_SZ=2  Const REG_BINARY=3  Const REG_DWORD=4  Const REG_MULTI_SZ=7    Const HKCU_IE_PROXY = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"    Set oReg=GetObject("winmgmts:!root/default:StdRegProv")  strComputer = "."  Set objWMIService = GetObject("winmgmts:" _      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    Set colProcessList = objWMIService.ExecQuery _      ("Select * from Win32_Process Where Name = 'iexplore.exe'")    Main    Sub Main()  	resp = msgbox("All internet explorer windows must be closed in order to continue" & vbCrLf & "Click Yes to close them now or No to cancel", vbYesNo)  	If resp = vbNo Then  		'Nothing To do  	Else  		For Each objProcess in colProcessList  			objProcess.Terminate()  		Next  		If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 And Len(GetValue(HKCU,HKCU_IE_PROXY,"ProxyServer",REG_SZ)) > 0 Then  			CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",0,REG_DWORD  			wscript.echo "Proxy Disabled"  		Else  			strProxyServer = "PROXYNAME:PORT"  			strProxyOveride = "*.EXCEPTIONS"    			CreateValue HKCU,HKCU_IE_PROXY,"ProxyServer",strProxyServer,REG_SZ  			CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",1,REG_DWORD  			CreateValue HKCU,HKCU_IE_PROXY,"ProxyOverride",strProxyOveride,REG_SZ  			wscript.echo "Proxy Enabled" & vbcrlf & "(" & strProxyServer & ")"  		End If  	End If    End Sub    Function CreateValue(Key,SubKey,ValueName,Value,KeyType)  Select Case KeyType  Case REG_SZ  CreateValue = oReg.SetStringValue(Key,SubKey,ValueName,Value)  Case REG_EXPAND_SZ  CreateValue = oReg.SetExpandedStringValue(Key,SubKey,ValueName,Value)  Case REG_BINARY  CreateValue = oReg.SetBinaryValue(Key,SubKey,ValueName,Value)  Case REG_DWORD  CreateValue = oReg.SetDWORDValue(Key,SubKey,ValueName,Value)  Case REG_MULTI_SZ  CreateValue = oReg.SetMultiStringValue(Key,SubKey,ValueName,Value)  End Select  End Function    Function DeleteValue(Key, SubKey, ValueName)  DeleteValue = oReg.DeleteValue(Key,SubKey,ValueName)  End Function    Function GetValue(Key, SubKey, ValueName, KeyType)    Dim Ret    Select Case KeyType  Case REG_SZ  oReg.GetStringValue Key, SubKey, ValueName, Value  Ret = Value  Case REG_EXPAND_SZ  oReg.GetExpandedStringValue Key, SubKey, ValueName, Value  Ret = Value  Case REG_BINARY  oReg.GetBinaryValue Key, SubKey, ValueName, Value  Ret = Value  Case REG_DWORD  oReg.GetDWORDValue Key, SubKey, ValueName, Value  Ret = Value  Case REG_MULTI_SZ  oReg.GetMultiStringValue Key, SubKey, ValueName, Value  Ret = Value  End Select    GetValue = Ret  End Function

If you would like to add more areas of the settings dialog box to the script, load the hive in the registry and make the changes as required.  Refresh your registry viewer and then add the values to the script as required.

Remember…For the above code to work you will need to change the proxy name and port to reflect your own.

This script has been tested and proved to work on Windows 7.

  • Pingback: Set Internet Explorer Proxy settings using VBScript

  • Patrick Weichel

    Any change for Win 7 64 bit?  I’m just a novice scripter…but there is a reference here to Win32_Process?   Thanks!

    • http://www.mikesel.info/ Mike Hudson

      Hi Patrick

      I’ve just tested this on a 64 bit win 7 machine, an despite the fact the script relates to 32 bit it also affects the 64 bit IE browser.


      • Patrick Weichel

        Thanks Mike. It is working well. I’m putting this in a login script as we are still having issues with GPO’s not applying on two groups of Win 7 64 Bit with IE 9. MS KB 825685 is similar issue, except I’m not using GPPs. Our GPO does everything except consistently set the Proxy value under these circumstances.  I’ve spent the better part of the week trying to get it working with Policy…at least this script is working!

  • Irfan Ahmed

    thanks a lot … changed PROXYNAME:PORT and worked without any trouble. fyi it works perfectly on Win8 (64bit)

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!