Modify Your Proxy Settings For Internet Explorer (VBScript)


To totally unlock this section you need to Log-in


Login

One common thing many people do to protect their identity when visiting certain websites or while working on the Internet while away from home, is to make use of proxy servers. Anonymous proxy servers will hide your real IP, which is useful if you’ve been banned from certain forums or websites for any reason, but people also use proxy servers for business reasons as well.

When you’re at the office, you may want to use your company’s internal proxy servers to access the Internet, but while you’re roaming or at home you just want your computer to automatically detect proxy settings.

Where A Proxy Server Is Configured

Before we get into the ways that you can automate your computer through scripting, let’s take a quick look at the manual way people would have to do this. Most people know how to configure their LAN settings – it’s one of the first things you should check if you’re ever having Internet connection problems. Typically you want your proxy settings to be set to “Automatically detect settings” when you’re at home or at a public hotspot.

However, at work, you’ll need to set up a proxy server. You do this within “Internet Properties” in the control panel by clicking on the “LAN settings” button.

Modify Your Proxy Settings For Internet Explorer (VBScript)

Inside your network settings dialog, you’ll see the two settings – you either have a proxy server enabled or you don’t. This is the setting that you want to toggle when you switch from your home network to a work network, or if you want to switch to running under a “cloaked” anonymous IP server.

Modify Your Proxy Settings For Internet Explorer (VBScript)

You can also find these settings in your registry (click Run and type “regedit“), and this is what you want your scripts to edit. By changing the registry settings, you’re essentially changing those settings in the LAN Settings window.

Modify Your Proxy Settings For Internet Explorer (VBScript)

What we really want to do is toggle those settings only when and where you really want to. There are three scenarios that I’m going to cover, and you can copy and paste the code to tweak it to your liking. You can put the script in your startup folder so that it launches whenever you boot your computer, or you can just run the scripts whenever you want your computer to automatically set the correct IP settings.

The three scenarios I’m going to provide scripts for include the following.

  • Prompt the user whether or not they want to use an anonymous proxy for Internet access.
  • Prompt the user to type in the name of the proxy server they want to use.
  • Automatically check whether you’re home or not, and set the appropriate proxy server settings.

The cool thing about Windows Scripting Host is that each of these options aren’t that hard to do.

Ask User To Enable A Proxy Server

This script will pop-up a message box asking whether or not the user wants to use a proxy server. If yes, then the script will enable proxy servers and fill in a hard-coded anonymous proxy server. You can tweak the script to use your favorite anonymous proxy. Here’s what the script looks like:

<script language="VBScript">

Option Explicit
Dim valUserIn
Dim objShell, RegLocate, RegLocate1
Set objShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
valUserIn = MsgBox("Use A Cloaked Proxy?",4,"Cloaked Select")
If valUserIn=vbYes Then
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
objShell.RegWrite RegLocate,"http://www.youareanonymous.com:80","REG_SZ"
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"1","REG_DWORD"
MsgBox "Cloaked Proxy is Enabled"
else
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
objShell.RegWrite RegLocate,"0.0.0.0:80","REG_SZ"
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"0","REG_DWORD"
MsgBox "Cloaked Proxy is Disabled"
End If
WScript.Quit
</script>

When you run it, the user sees the following prompt:

Modify Your Proxy Settings For Internet Explorer (VBScript)

A “Yes” loads the anonymous proxy as your proxy server and sets “ProxyEnable” to 1. A “No” sets the proxy to default all zeros, and disables the proxy setting.

Prompt User To Type Proxy

The other approach is to ask the user what exact server they want to use. This allows the flexibility of changing the proxy server constantly without the need to edit the script itself. You can do this by changing the “MsgBox” command to an “InputBox”.

<script language="VBScript">

Option Explicit
Dim valUserIn
Dim objShell, RegLocate, RegLocate1
Set objShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
valUserIn = Inputbox("Enter the Proxy server you want to use.","Proxy Server Required")
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
objShell.RegWrite RegLocate,valUserIn,"REG_SZ"
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"1","REG_DWORD"
MsgBox "Proxy is Enabled"
WScript.Quit </script>

When you save this as a .wsf file and run it, the following window will appear.

Modify Your Proxy Settings For Internet Explorer (VBScript)

Just type in your preferred proxy server, click okay, and your Internet settings are automatically updated.

Set Proxy Settings Based On Location

This next script is a little bit more flexible, so it’s also a little longer. But what it can do is check your current IP address, and if it is within the range that you expect when you’re on your home ISP, it’ll disable using a proxy server. If it sees that you’re not on your typically home IP domain, it’ll automatically configure your internet with a proxy server that you can hard code into the script.

Here’s what the script looks like.

<script language="VBScript">

Option Explicit
Dim valUserIn
Dim objShell, RegLocate, RegLocate1
Dim objRemXML
Dim objMyIP
Dim strIPAddress
Dim strHostname
Dim strHomeDomain
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Const cstrShowMyIP = "http://www.showmyip.com/xml/"
Set objRemXML = CreateObject("Microsoft.XMLDOM")
objRemXML.async = False
objRemXML.load(cstrShowMyIP)
' Get our IP address
Set objMyIP = objRemXML.selectSingleNode("/ip_address/ip")
strIPAddress = objMyIP.text
' Print info
WScript.Echo "IP address : " & strIPAddress
strHomeDomain = Left (strIPAddress,6)
If strHomeDomain = "69.161" then
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
objShell.RegWrite RegLocate,"0.0.0.0:80","REG_SZ"
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"0","REG_DWORD"
MsgBox "Cloaked Proxy is Disabled"
else
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
objShell.RegWrite RegLocate,"http://www.youareanonymous.com:80","REG_SZ"
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"1","REG_DWORD"
MsgBox "Cloaked Proxy is Enabled"
end if
' Finish
Set objMyIP = Nothing
Set objRemXML = Nothing
WScript.Quit
</script>

You set set this up to run on startup, and the computer will automatically configure the Internet settings as needed. The program will show you your current IP each time – if you don’t want that, just remove the “WPScript.Echo” line. When I run it here at home, it recognizes I’m on my safe home ISP and disables the anonymous proxy.

Modify Your Proxy Settings For Internet Explorer (VBScript)

If you were on a public hotspot, it would recognize the foreign IP address and enable the cloaked proxy instead.
These are just a few examples of the sort of automation you can build into your Windows PC with Windows Scripting Host.