在 Windows 中,我想使用批处理脚本禁用 Internet选项中的代理服务器设置。 我可以使用什么命令来执行此操作?
如果不确定我指的是什么,请参阅
Internet Properties > Connections > LAN Settings >Proxy Server
谢谢
答案 0 :(得分:18)
它位于注册表中 [HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings]
您可以在BAT中使用REG
命令,也可以准备几个.REG
文件,以自动执行更改。
例如,要禁用代理,请尝试
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
答案 1 :(得分:10)
使用.vbs启用上的代理和关闭
此.vbs MS脚本确定当前代理设置并切换到反对设置 如果你想打开和关闭代理,非常方便
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
答案 2 :(得分:8)
这是一种使用简单的.vbs脚本作为“窗口小部件”类型桌面快捷方式的方法。第一次要运行脚本时,单击您创建的.vbs文件。这将使用适当的图标自动为您生成桌面快捷方式。每次单击此后的快捷方式时,它都会切换代理设置,打开一个定时弹出框1秒钟,告诉您代理现在是 ON 还是 OFF ,并且更改ON或OFF符号的快捷图标,表示新的代理状态。
文件:“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
从现在开始,只需单击“代理开关”桌面快捷方式,即可打开和关闭代理。
以下是代理关闭时的样子:
以下是代理开启时的样子:
这是每当您单击快捷方式图标以打开/关闭代理时出现的1秒弹出窗口的示例。
有人可以帮助我弄清楚如何通过每次更改图标名称来进一步提高这一点吗? - 即:而不是在快捷方式上说“代理开关”,有它根据目前的状态,说“代理开启”或“代理关闭”。我不确定如何更进一步,我现在已经有足够的时间了。
答案 3 :(得分:7)
Internet Explorer和Google Chrome共享相同的代理设置。因此,如果我们更改Internet Explorer中的设置,那么它也会影响Google Chrome。我们可以从CMD(命令行提示符)更改代理设置。
禁用代理设置:
@ECHO OFF
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
启用代理设置:
@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
:新的代理地址
portNumber
:端口号
将命令保存在批处理文件中并执行它。它将禁用/启用浏览器的代理设置。
我在http://langbasics.blogspot.in/2012/11/disable-or-enable-proxy-for-internet.html
找到了这个答案答案 4 :(得分:1)
禁用代理
REG添加“ HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet设置” / v ProxyEnable / t REG_DWORD / d 0 / f
启用代理
reg添加“ HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet设置” ^ / v ProxyEnable / t REG_DWORD / d 1 / f
设置代理
reg添加“ HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet设置” ^ / v ProxyServer / t REG_SZ / d ProxyServerIP:Port / f
答案 5 :(得分:1)
感谢@Gabriel Staples的回答 https://stackoverflow.com/a/44752679/6070417
请首先执行步骤
但是有两点需要注意:
1,就像@afxentios在评论中说的那样:
需要更正。在用户名=> WSHShell.ExpandEnvironmentStrings(“%USERNAME%”)下添加以下行:ProxySettings_path =“ C:\ Users \” +用户名+>“ \ Proxy Settings”,然后删除硬编码路径。
修复步骤
a)将此行添加到第26行下的 toggle_proxy_on_off.vbs :
ProxySettings_path = "C:\Users\" + username + "\Proxy Settings"
b)删除第18行 ProxySettings_path =“ C:\ Users \ Gabriel \ Proxy设置” 。
2,您将看到脚本确实更新了注册表,但是直到您打开/关闭IE一次它才起作用。因此,我在这里找到了答案:https://stackoverflow.com/a/39079005/6070417
修复步骤
a)复制脚本打击并保存到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)将文件Refresh-System.ps1放入“ C:\ Users \ YOUR_USERNAME \ Proxy设置”
c)将此行添加到“结束条件”下的 toggle_proxy_on_off.vbs (大约35行)
WSHShell.run("powershell -windowstyle hidden -file """ + ProxySettings_path + "\Refresh-System.ps1""")
该脚本将在没有IE的情况下运行。
。
但是现在,当vbs脚本调用powershell脚本时,powershell窗口将显示一会儿。
谁知道如何设置Powershell窗口永不显示?请添加评论。
答案 6 :(得分:0)
我写了一个带有“启用/禁用代理”选项的脚本,该脚本以管理员身份启动。您只需要将其复制到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
答案 7 :(得分:0)
试试这个来禁用代理。 PA 接受的答案会更改注册表中的值,但要使更改生效,如注释中所述,必须重新启动 IE。
将下一个内容保存为 cmd- 或 bat- 文件并运行它:
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
如果您想将代理切换为“打开”(或 1),您可以这样做:
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