In Windows, I want to disable the Proxy Server setting in Internet Options by using a batch Script. What command can I use to do this?
If unsure what I am referring to, see
Internet Properties > Connections > LAN Settings >Proxy Server
Thank you
It's in the registry, under [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
you can either use the REG
command in your BAT, or prepare a couple of .REG
files, to automate the changes.
for example, to disable Proxy, try
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
Update 25 May 2021: get the icons and latest script from my GitHub repo here now: Windows_Proxy_Toggler. See the super-simple installation instructions there too.
Here is a way using a simple .vbs script as a "widget" type desktop shortcut. The first time you want to run the script, click the .vbs file you create. This will automatically generate a desktop shortcut for you with an appropriate icon. Each time you click the shortcut thereafter it toggles the proxy setting, brings up a timed popup box for 1 sec to tell you whether the proxy is ON or OFF now, and changes the shortcut icon to an ON or OFF symbol to indicate the new proxy state.
File: "C:\Users\YOUR_USERNAME\Proxy Settings\toggle_proxy_on_off.vbs"
'Toggle your Proxy on and off
'Gabriel Staples - www.ElectricRCAircraftGuy.com
'Written: 21 June 2017
'Updated: 25 June 2017
'References:
' 1) https://stackoverflow.com/a/27092872/4561887
' 2) https://stackoverflow.com/a/26708451/4561887
' Timed message boxes:
' - *****https://technet.microsoft.com/en-us/library/ee156593.aspx
' - https://stackoverflow.com/questions/14105157/automatically-close-msgbox-in-vbscript
' Debug output:
' - ex: Wscript.Echo "here is your message"
Option Explicit
'Variables & Constants:
Dim ProxySettings_path, VbsScript_filename
ProxySettings_path = "C:\Users\Gabriel\Proxy Settings"
VbsScript_filename = "toggle_proxy_on_off.vbs"
Const MESSAGE_BOX_TIMEOUT = 1 'sec; change this value to set how long the message box displays when you toggle the proxy setting
Const PROXY_OFF = 0
Dim WSHShell, proxyEnableVal, username
Set WSHShell = WScript.CreateObject("WScript.Shell")
'get the username string for use in path names, since trying to use the "%USERNAME%" variable directly in path names throws an error
username = WSHShell.ExpandEnvironmentStrings("%USERNAME%")
'Determine current proxy setting and toggle to opposite setting
proxyEnableVal = wshshell.regread("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If proxyEnableVal = PROXY_OFF Then
TurnProxyOn
Else
TurnProxyOff
End If
'Subroutine to Toggle Proxy Setting to ON
Sub TurnProxyOn
'turn proxy on via a registry entry
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
'create/update desktop shortcut
CreateOrUpdateDesktopShortcut("on")
'notify user via an auto-timed popup box
WSHShell.Popup "Internet proxy is now ON", MESSAGE_BOX_TIMEOUT, "Proxy Settings"
End Sub
'Subroutine to Toggle Proxy Setting to OFF
Sub TurnProxyOff
'turn proxy off via a registry entry
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
'create/update desktop shortcut
CreateOrUpdateDesktopShortcut("off")
'notify user via an auto-timed popup box
WSHShell.Popup "Internet proxy is now OFF", MESSAGE_BOX_TIMEOUT, "Proxy Settings"
End Sub
'Subroutine to create or update a shortcut on the desktop
Sub CreateOrUpdateDesktopShortcut(onOrOff)
'create a shortcut
Dim shortcut, iconStr
Set shortcut = WSHShell.CreateShortcut("C:\Users\" + username + "\Desktop\Proxy On-Off.lnk")
'Set the target path (target file) to run when the shortcut is clicked
shortcut.TargetPath = ProxySettings_path + "\" + VbsScript_filename
'Set the working directory. This is necessary in case you ever make this shortcut call a batch (.bat) file, for instance, which in turn calls a .vbs script. In order to know where the .vbs script file/command is located, the shortcut must be operating in the working directory where the .vbs scripts are located. Otherwise, calls to the .vbs scripts from a .bat file this shortcut points to, for instance, won't work since their directories are not in the Windows %PATH% variable, and you'll get an error which states: "'name_of_vbs_script_file' is not recognized as an internal or external command, operable program or batch file."
shortcut.WorkingDirectory = ProxySettings_path
'Set the icon to associate with this shortcut
If onOrOff = "on" Then
iconStr = "on.ico"
ElseIf onOrOff = "off" Then
iconStr = "off.ico"
End If
shortcut.IconLocation = ProxySettings_path + "\Icons\" + iconStr
'Save the shortcut
shortcut.Save
End Sub
From this point on, just click the "Proxy On-Off" desktop shortcut directly to toggle the Proxy on and off.
Here's what it looks like when the Proxy is OFF:
Here's what it looks like when the Proxy is ON:
Here's an example of the 1-second popup window that comes up whenever you click the shortcut icon to toggle the Proxy on/off.
Can someone please help me figure out how to enhance this one step further by making it change the icon name each time too?--ie: instead of saying "Proxy On-Off" on the shortcut, have it say "Proxy is ON" or "Proxy is OFF", according to its current state. I'm not sure how to take it that one step further, and I've put enough time into it for now...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With