Script Sharp 1 – Scripting Internet Explorer proxy configuration
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.












But why don’t you use a proxy.pac?
I have one on my pc, that automatically switches proxy depending on the IP of my primary network adapter. Thus, the choice of the correct proxy is somewhat automatic. The file I use is similar to this one:
function FindProxyForURL(url,host) {
if(isPlainHostName(host))
return "DIRECT";
else if(isInNet(host,"127.0.0.0","255.0.0.0"))
return "DIRECT";
else if(isInNet(host,"192.168.0.0","255.255.0.0")) // VMWare & Wi-Fi
return "DIRECT";
else if(isInNet(myIpAddress(),"172.16.0.0","255.255.0.0")) // BF
return "PROXY 172.16.0.170:8080;DIRECT";
else
return "DIRECT";
}
I even found that you do not need an http service (i.e. a local IIS or Apache) to give back the .pac file: you can simply use a URL syntax with the “file:” prefix, like:
file:///drive/path/proxy.pac
This is the configuration for Firefox, I think that with IE you must use only two slashes after the “file:”. I think that if you have any http service on your pc, it is better to specify an “http://localhost/…” path to reach your proxy.pac file, because some other tools that use the IE proxy can get confused by the “file:” syntax…
Wonderful! the final solution.