Pinterest Stumbleupon Whatsapp
Ads by Google

proxy settingsRecently, I’ve become quite obsessed with computer automation. After writing a recent article about Windows Scripting with VB script Better Than Batch: A Windows Scripting Host Tutorial Better Than Batch: A Windows Scripting Host Tutorial Read More (a programming language I love), I’ve started exploring different ways people can make their computer smarter through scripts.

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 How To Test Your Home Network Speed (And Decipher The Results) How To Test Your Home Network Speed (And Decipher The Results) Read More – 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

Ads by Google

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.

Image credit: Mr. Gr4phic3r

  1. Edinra
    August 10, 2016 at 10:12 am

    hi,
    I tried to use the first script, but it is used only to check and uncheck the proxy. It doesnt process it.
    Once I disable this means, again i open new tab, its not disabled..

    The problem is there is no code for pressing enter key.

    The OK button in proxy.

    Please any one help.

  2. snehal
    July 4, 2016 at 1:06 pm

    I tried script 1, it works but new proxy setting are not applied till I restart internet explorer. Any idea?

  3. Bala
    January 21, 2016 at 8:17 am

    hi This is bala,

    My client system didnot get the automatic proxy script. We have to enable manually. what could i do....

  4. rhabanna
    November 24, 2015 at 4:26 pm

    Thanks for this. Would you happen to know how to get the checkbox next to "use automatic proxy" checked using the prompt user to set proxy script? It works fine but does not check the box so explorer will not address the auto proxy that it set.

  5. Jalel
    May 24, 2015 at 8:09 pm

    Thanks for this post I found it helpful.
    I was looking for a script to just enable or disable the proxy. I switch too often this option and wanted to automate it.
    I modified the first script to just modify the RegLocate = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsProxyEnable"
    I removed the other RegLocate statements.
    *Jalel

  6. jim
    April 23, 2015 at 7:13 pm

    Appreciate the tip, needed to update an exclusions list. This worked perfectly.

  7. Shreejeet
    April 13, 2015 at 4:26 am

    Hi Ryan,

    Thanks, This is what I'm looking for but I'm trying to do same thing using C#.
    Is it possible to use this?

  8. Anonymous
    February 6, 2011 at 10:29 pm

    Thanks Tim - that's right, the "textarea" tag shouldn't be there, only the text within the tags, thanks for catching that.

  9. rdube02
    February 6, 2011 at 11:29 pm

    Thanks Tim - that's right, the "textarea" tag shouldn't be there, only the text within the <job> tags, thanks for catching that.</job>

  10. Anonymous
    February 6, 2011 at 4:34 pm

    @James888
    I noticed that the first script in the article has a tag hanging at the end. That is likely a remnant of the author cut/paste operation and shouldn't be there. I'm not on a Windows machine to test right now but I would assume that error would cause the VB compiler to fail, as you're seeing. Remove that last tag and try it again.

  11. timpala
    February 6, 2011 at 5:34 pm

    @James888
    I noticed that the first script in the article has a tag hanging at the end. That is likely a remnant of the author cut/paste operation and shouldn't be there. I'm not on a Windows machine to test right now but I would assume that error would cause the VB compiler to fail, as you're seeing. Remove that last tag and try it again.

  12. Aibek
    January 5, 2011 at 10:54 am

    That will be an ideal question for MakeUseOf Answers, http://www.makeuseof.com/answe...

  13. Anonymous
    December 31, 2010 at 6:23 am

    Ask User To Enable A Proxy Server script. I put the script in and it has an error.

    Script: C:...
    Line: 1
    Char: 1
    Error: Expected statement
    Code: 800A0400
    Source: Microsoft VBScript compilation error

    Im dont know VBS script to well so I couldnt fix it. Looked it up and read the obvious, that there is an error with the first line. Im going to continue to try and get it working.
    If anyone knows whats wrong please post in comments.

  14. james888
    December 31, 2010 at 7:23 am

    Ask User To Enable A Proxy Server script. I put the script in and it has an error.

    Script: C:\...
    Line: 1
    Char: 1
    Error: Expected statement
    Code: 800A0400
    Source: Microsoft VBScript compilation error

    Im dont know VBS script to well so I couldnt fix it. Looked it up and read the obvious, that there is an error with the first line. Im going to continue to try and get it working.
    If anyone knows whats wrong please post in comments.

  15. jrmbtr
    December 30, 2010 at 2:07 am

    How do you find a good proxy? Any that I try won't work with most sites.

  16. saurabh
    December 29, 2010 at 10:35 pm

    that's some cool stuff..but will it be ok for an ordinary user to keep editing his regedit through scripts all the time? Will he be able to fix some issue that may crop up?

  17. saurabh
    December 29, 2010 at 11:35 pm

    that's some cool stuff..but will it be ok for an ordinary user to keep editing his regedit through scripts all the time? Will he be able to fix some issue that may crop up?

Leave a Reply

Your email address will not be published. Required fields are marked *