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
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
On
Turn proxy on and off with a .vbs
This .vbs MS Script Determine current proxy setting and toggle to oppisite setting very handy if you want to turn proxy on and off
Option Explicit
Dim WSHShell, strSetting
Set WSHShell = WScript.CreateObject("WScript.Shell")
'Determine current proxy setting and toggle to oppisite setting
strSetting = wshshell.regread("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable")
If strSetting = 1 Then
NoProxy
Else Proxy
End If
'Subroutine to Toggle Proxy Setting to ON
Sub Proxy
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
End Sub
'Subroutine to Toggle Proxy Setting to OFF
Sub NoProxy
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
End Sub
On
Try this to disable the proxy. PA's accepted answer changes the values in the registry, but for changes to take effect, as noted in the comments, it is necessary to restart IE.
Save the next content as cmd- or bat-file and run it:
REM turn off proxy server setting
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
REM restart IE for changes to take effect
start /w /b iexplore.exe
taskkill /f /im iexplore.exe
If you would like to toggle proxy to "on" (or 1), you could do:
REM turn on proxy server setting
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
REM you would likely also want to specify your proxy server and port
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d ADDRESS:PORT /f
REM restart IE for changes to take effect
start /w /b iexplore.exe
taskkill /f /im iexplore.exe
This was checked on Windows 7 and Windows 10. See more here and here.
On
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...
On
Internet explorer and Google chrome both shares same proxy settings. So if we change setting in internet explorer, then it also effects in Google chrome. We can change proxy setting from CMD (command line prompt).
Disable proxy setting:
@ECHO OFF
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
Enable proxy setting:
@ECHO OFF
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d address:portNumber /f
address: New proxy address
portNumber: Port Number
Save the commands in a batch file and execute it. It will disable/enable the proxy setting for browser.
I found this answer at: http://langbasics.blogspot.in/2012/11/disable-or-enable-proxy-for-internet.html
On
Disable the proxy
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
Enable the proxy
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^ /v ProxyEnable /t REG_DWORD /d 1 /f
Set the proxy
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^ /v ProxyServer /t REG_SZ /d ProxyServerIP:Port /f
On
I wrote a script with "enable/disable proxy" options and that starts as Administrator. you just need to copy it to a file.bat:
@echo off
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
@echo off
Setlocal EnableDelayedExpansion
:MAIN_M
ECHO
ECHO
ECHO 0. QUIT
ECHO 1. ENABLE PROXY 10.10.10.10:8181
ECHO 2. DISABLE PROXY
set /p choice=CHOISE....
if ´%choice%´==´0´ goto EXIT_M
if ´%choice%´==´1´ goto ENABLE_PROXY
if ´%choice%´==´2´ goto DISABLE_PROXY
:EXIT_M
exit
:DISABLE_PROXY
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
goto MAIN_M
:ENABLE_PROXY
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d 10.10.10.10:8181 /f
goto MAIN_M
On
Thanks the answer from @Gabriel Staples https://stackoverflow.com/a/44752679/6070417
Just do as the steps first,
but there is two things should to be watched:
1, Like @afxentios said in comment:
A correction is needed. Add the line: ProxySettings_path = "C:\Users\" + username + >"\Proxy Settings" under the line username = >WSHShell.ExpandEnvironmentStrings("%USERNAME%") and remove the hard coded path.
Fix Steps
a) Put this line to toggle_proxy_on_off.vbs under line 26:
ProxySettings_path = "C:\Users\" + username + "\Proxy Settings"
b) Remove line 18 ProxySettings_path = "C:\Users\Gabriel\Proxy Settings".
2, You will see the script indeed update the registry, but it won't work until you open/close IE once. So I found the answer here: https://stackoverflow.com/a/39079005/6070417
Fix Steps
a) Copy the script blow and save to Refresh-System.ps1
function Refresh-System
{
$signature = @'
[DllImport("wininet.dll", SetLastError = true, CharSet=CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
'@
$INTERNET_OPTION_SETTINGS_CHANGED = 39
$INTERNET_OPTION_REFRESH = 37
$type = Add-Type -MemberDefinition $signature -Name wininet -Namespace pinvoke -PassThru
$a = $type::InternetSetOption(0, $INTERNET_OPTION_SETTINGS_CHANGED, 0, 0)
$b = $type::InternetSetOption(0, $INTERNET_OPTION_REFRESH, 0, 0)
return $a -and $b
}
Refresh-System
b) Put file Refresh-System.ps1 to "C:\Users\YOUR_USERNAME\Proxy Settings"
c) Add this line to toggle_proxy_on_off.vbs under "End If"(about line 35)
WSHShell.run("powershell -windowstyle hidden -file """ + ProxySettings_path + "\Refresh-System.ps1""")
The script will work without IE.
.
But now when vbs script call powershell script, the powershell window will appear a short moment.
Who knows how to set the powershell window never show? please add a comment.
It's in the registry, under [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
you can either use the
REGcommand in your BAT, or prepare a couple of.REGfiles, to automate the changes.for example, to disable Proxy, try