pro*_*ngs 48 windows windows-7 proxy batch-file
如何在 Windows 7 中从命令行更改代理设置?
我不只是在谈论http_proxy
. 我需要设置系统范围的代理设置(Internet 属性设置中的设置)。我怎么做?
say*_*yap 64
从http://www.ehow.com/how_6887864_do-proxy-settings-command-prompt_.html检索的简单而有效的解决方案
启用代理使用的命令:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 1 /f
Run Code Online (Sandbox Code Playgroud)
禁用代理使用的命令:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 0 /f
Run Code Online (Sandbox Code Playgroud)
更改代理地址的命令:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /f
Run Code Online (Sandbox Code Playgroud)
我添加了换行符 (^) 以提高可读性。此外,在这种情况下,它更像是每个用户的设置而不是系统范围的设置。
小智 16
您需要配置一个注册表脚本,该脚本将通过控制面板进行您通常会进行的更改,然后合并该脚本以启用代理。您还需要一个“撤消”注册表脚本来禁用更改。
就我而言,我有两个脚本,enable.reg 和 disable.reg:
启用代理:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"AutoConfigURL"="http://10.10.10.1/autoproxy/proxy.pac"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
"DefaultConnectionSettings"=hex:16,00,00,00,05,02,00,00,0d,00,00,00,0e,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
"SavedLegacySettings"=hex:36,00,00,00,46,1a,00,00,0d,00,00,00,0e,00,00,00,32,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
Run Code Online (Sandbox Code Playgroud)
禁用代理:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"AutoConfigURL"=-
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections]
"DefaultConnectionSettings"=hex:16,00,00,00,05,02,00,00,0d,00,00,00,0e,00,00,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
"SavedLegacySettings"=hex:36,00,00,00,46,1a,00,00,0d,00,00,00,0e,00,00,00,32,\
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
Run Code Online (Sandbox Code Playgroud)
在“禁用”脚本中,=-
AutoConfigURL 的末尾实际上从注册表中删除了该键。
请注意,您在上面看到的值已针对此答案进行了修改。实际的十六进制值要长得多。
为了使用这些脚本,我为每个脚本准备了一个批处理文件,如下所示:
@echo off
start /min reg import C:\Path\To\Registry\File\enable_proxy.reg
Run Code Online (Sandbox Code Playgroud)
这在命令行中完全可行。
小智 5
我是用 C# 完成的,但原理是相同的,写入注册表,因此以下指令可以推断为行命令。应当做好三件事:
写入注册表“HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”,在 ProxyEnable 上:1 启用,0 禁用
写入注册表“HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings”,在代理服务器上:xxx.xxx.xxx.xxxx:yyyy(xxx...是IP,yy..是端口)
执行步骤 1 和 2 后,您将写入注册表激活代理以及 IP 和端口,但如果您打开浏览器,您会发现这还不够,您还无法导航。第三步包括更改有关连接设置的注册表:
“DefaultConnectionSettings”上的“Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections”。
请注意,虽然(至少对于 W7)此注册表中有 204 个字节,但您只需修改字节 8(第 9 个字节,因为字节 0 是第一个字节)。字节 8 值不仅包含有关代理启用/禁用的信息,还包含有关其他功能的信息:
//09 when only 'Automatically detect settings' is enabled
//03 when only 'Use a proxy server for your LAN' is enabled
//0B when both are enabled
//05 when only 'Use automatic configuration script' is enabled
//0D when 'Automatically detect settings' and 'Use automatic configuration script' are enabled
//07 when 'Use a proxy server for your LAN' and 'Use automatic configuration script' are enabled
//0F when all the three are enabled.
//01 when none of them are enabled.
Run Code Online (Sandbox Code Playgroud)
就我而言,“自动检测设置”始终处于启用状态,因此我将字节 8 的值从 09 切换到 0B,反之亦然,以启用和禁用代理。