在 Windows 7 中,如何從命令列更改代理設定?

在 Windows 7 中,如何從命令列更改代理設定?

如何在 Windows 7 中透過命令列更改代理設定?

我不只是在談論http_proxy.我需要設定係統範圍的代理設定(Internet 屬性設定中的代理設定)。我怎麼做?

答案1

您需要配置一個註冊表腳本,該腳本將進行通常透過控制面板進行的更改,然後合併該腳本以啟用代理程式。您還需要一個「撤銷」註冊表腳本來停用變更。

就我而言,我有兩個腳本,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

禁用代理:

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

在「停用」腳本中,=-AutoConfigURL 末尾的 實際從註冊表中刪除了該金鑰。

請注意,您在上面看到的值是出於此答案的目的而修改的。實際的十六進制值要長得多。

為了使用這些腳本,我為每個腳本建立了一個批次文件,如下所示:

@echo off
start /min reg import C:\Path\To\Registry\File\enable_proxy.reg

這完全可以透過命令列進行操作。

答案2

簡單且可行的解決方案取自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

禁用代理程式使用的命令:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
    /v ProxyEnable /t REG_DWORD /d 0 /f

更改代理地址的命令:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
    /v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /f

我添加了續行 (^) 以提高可讀性。此外,在這種情況下,它更像是每個用戶設定而不是系統範圍設定。

答案3

網路瀏覽器來救援!

NetSh winhttp set proxy 應該有幫助。以下是命令:

netsh winhttp set proxy myproxy

netsh winhttp set proxy myproxy:80 "<local>bar"

netsh winhttp set proxy proxy-server="http=myproxy;https=sproxy:88" bypass-list="*.contoso.com"

答案4

建立一個批次檔並貼上以下內容(它將切換代理狀態),

@echo off

FOR /F "tokens=2* delims=    " %%A IN ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') DO SET currentProxy=%%B
rem ECHO currentProxy=%currentProxy%

if %currentProxy%==0x1 (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
echo Proxy Disabled
) else (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
echo Proxy Enabled
  )

pause

相關內容