Script Sharp 1 – Scripting Internet Explorer proxy configuration

2

Posted on : 12-03-2007 | By : matteosp | In : Miscellaneous, Scriptings

This is for those who continuously have to configure Internet Explorer proxy settings to match different network locations.

I have two different configurations I’m switching at least twice a day: one for when I’m in the office and another for my home WI-FI network. Not to talk about the number of configurations I have for the customers I sometimes have to visit.

Script must be included in a .vbs file that you can call directly from the shell or with a shortcut.

Here the code you can run to enable/disable proxy:

On Error Resume Next

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."
strKeyPath = "SoftwareMicrosoftWindowsCurrentVersionInternet Settings\"

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}" & strComputer & "rootdefault:StdRegProv")
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, "ProxyEnable", 1 'Use 0 to disable proxy
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, "ProxyServer", "proxyName:8080"

If err.Number <> 0 Then
    MsgBox err.Description
End If

MsgBox "Done!"

Note that you can work on a different machines (strComputer) and impersonate a desired user (the WMI string passed to GetObejct() function), but I haven’t investigated this yet.