Turn proxy on or off script for Microsoft Windows

Here I want to share a script that my friend selflessly shared with me:)

In a nutshell this script detects on which network you are connected and then turns the proxy on or off. The only thing you need to change is the value (“172.”) in the “isproxynetworkip” line. This value defines what kind of IP address you use when connected to the network that needs proxy turned on (e.g. at work).


Copy and save the script as a .vbs file.


Set WshShell = CreateObject(“WScript.Shell”)

temp = “select IPAddress from Win32_NetworkAdapterConfiguration “& _
“where IPEnabled=TRUE”

temp2 = “winmgmts:{impersonationLevel=impersonate}”

TempReg = “HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable”

set IPConfigSet = GetObject(temp2).ExecQuery(temp)
isproxynetwork = 0
isproxynetworkip = “172.”
currentipaddress = “Not present”
currentipaddress1 = “Not present”

for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
currentipaddress1 = IPConfig.IPAddress(i)
if Left(currentipaddress1,Len(isproxynetworkip)) = isproxynetworkip then
isproxynetwork = 1
currentipaddress = currentipaddress1
end if
end if

if isproxynetwork = 1 then
WshShell.RegWrite TempReg,1,”REG_DWORD”
MsgBox “Proxy is ON”
WshShell.RegWrite TempReg,0,”REG_DWORD”
MsgBox “Proxy is OFF”
end if

There is also a nice way to do this automatically to setup a scheduled task with an event log trigger. This procedure will work only in Windows Vista and later. Here is a good explanation of it:


If you update the script with some new features – do share!:)

Leave a comment

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