3 Useful Scripts To Modify Your Proxy Settings For Internet Explorer

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.
proxy settings
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.
using batch file to set proxy settings
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.
how to set the proxy settings in the registry i
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.
  1. Prompt the user whether or not they want to use an anonymous proxy for Internet access.
  2. Prompt the user to type in the name of the proxy server they want to use.
  3. 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.

<job>
<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>
</job></textarea>
When you run it, the user sees the following prompt.
how to set the proxy settings in the registry
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”.

<job>
<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>
</job>
When you save this as a .wsf file and run it, the following window will appear.
how to set the proxy settings in the registry
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.

<job>
<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>
</job>
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.
proxy settings
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. You don’t have to be an expert programmer – just learn a few of the commands in these scripts and you can really work some magic.
Did you try any of these scripts? Let me know what you think, and please offer any tweaks or improvements that could make them even better. Offer your insight in the comments section below.

0 nhận xét:

Post a Comment