批处理文件禁用Internet选项代理服务器

Dex*_*ave 17 windows batch-file internet-options

Windows中,我想使用批处理脚本禁用" Internet选项"中的"代理服务器"设置.我可以使用什么命令来执行此操作?

如果不确定我指的是什么,请参阅

Internet Properties > Connections > LAN Settings >Proxy Server
Run Code Online (Sandbox Code Playgroud)

谢谢

PA.*_*PA. 19

它在[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]下的注册表中

您可以REG在BAT中使用该命令,也可以准备几个.REG文件来自动执行更改.

例如,要禁用代理,请尝试

REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
Run Code Online (Sandbox Code Playgroud)

  • 为了清楚起见,这就是我的工作,我运行蝙蝠,我尝试刷新页面(chrome已经打开!它抛出代理错误),我打开首选项并看到代理已被禁用,我重新刷新了页面这次加载页面。 (2认同)
  • 显然,它会取消选中“ Internet设置”上的“代理”复选框,但系统不会进行更改。它“视觉上”取消选中它,但是仍然需要触发该选项(就像您单击“接受”按钮一样)。 (2认同)

Gab*_*les 12

这是一种使用简单的.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 
Run Code Online (Sandbox Code Playgroud)

说明:

  1. 创建一个名为"C:\ Users\YOUR_USERNAME\Proxy Settings"的文件夹
  2. 在该文件夹中创建"toggle_proxy_on_off.vbs"文件,如上所示.
  3. 在此处创建"图标"文件夹:"C:\ Users\YOUR_USERNAME\Proxy Settings\Icons"
  4. 下载以下两个.png图片:
  5. 例如,使用http://icoconvert.com/将这些图像转换为图标(.ico文件).选择文件(从上面选择一个.png) - >上传 - >选择"ICO for Windows 7,Windows 8,Vista和XP"格式 - >点击"转换ICO" - >点击"下载你的图标(s )"
    • 将ON图标保存为"C:\ Users\YOUR_USERNAME\Proxy Settings\Icons\on.ico"
    • 将OFF图标保存为"C:\ Users\YOUR_USERNAME\Proxy Settings\Icons\off.ico"
  6. 现在,双击"C:\ Users\Gabriel\Proxy Settings\toggle_proxy_on_off.vbs"文件来运行它.它将自动在桌面上创建"代理开关"快捷方式文件,并带有相应的图标以指示代理是开启还是关闭.

从这一点开始,只需直接单击"代理开关"桌面快捷方式即可打开和关闭代理.

这是代理关闭时的样子:

在此输入图像描述

以下是代理开启时的样子:

在此输入图像描述

这是每当您单击快捷方式图标以打开/关闭代理时出现的1秒弹出窗口的示例.

在此输入图像描述

参考文献:

  1. /sf/answers/1896501071/ < - 教我如何使用.vbs脚本打开和关闭代理服务器
  2. /sf/answers/1869591601/ < - 通过创建Windows快捷方式并在每次单击时更改其图标,教我如何使.vbs脚本像窗口小部件一样工作的巧妙技巧
  3. 定时消息框:

去做:

有人可以帮我弄清楚如何通过每次更改图标名称来进一步提高这一点吗? - 即:而不是在快捷方式上说"代理开关",让它说"代理开启"或根据其当前状态"代理关闭".我不确定如何更进一步,我现在已经有足够的时间了...

  • 需要更正。在“用户名= WSHShell.ExpandEnvironmentStrings(“%USERNAME%”)”行下添加“ ProxySettings_path =“ C:\ Users \” +用户名+“ \ Proxy Settings”“行,并删除硬编码路径。 (2认同)

BOB*_*BOB 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
Run Code Online (Sandbox Code Playgroud)


小智 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
Run Code Online (Sandbox Code Playgroud)

启用代理设置:

@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
Run Code Online (Sandbox Code Playgroud)

address:新代理地址
portNumber:端口号

将命令保存在批处理文件中并执行它.它将禁用/启用浏览器的代理设置.

我在以下网址找到了这个答案:http://langbasics.blogspot.in/2012/11/disable-or-enable-proxy-for-internet.html

  • 虽然这会更改设置,但在我打开属性并单击"确定"之前,该设置对我不起作用.如何让它们真正生效? (7认同)