Windows 7 で、コマンド ラインからプロキシ設定を変更するにはどうすればよいですか?

Windows 7 で、コマンド ラインからプロキシ設定を変更するにはどうすればよいですか?

Windows 7 のコマンド ラインからプロキシ設定を変更するにはどうすればよいですか?

について話しているのではありませんhttp_proxy。システム全体のプロキシ設定 (インターネットのプロパティ設定にあるもの) を設定する必要があります。どうすればいいですか?

答え1

コントロール パネルから通常行う変更を行うレジストリ スクリプトを構成し、そのスクリプトをマージしてプロキシを有効にする必要があります。また、変更を無効にするには、「元に戻す」レジストリ スクリプトも必要です。

私の場合、enable.reg と disabled.reg という 2 つのスクリプトがあります。

プロキシを有効にする:

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

「disable」スクリプトでは、=-AutoConfigURL の末尾で実際にレジストリからキーが削除されます。

上記の値は、この回答のために変更されていることに注意してください。実際の 16 進値ははるかに長くなります。

これらのスクリプトを使用するために、スクリプトごとに次のようなバッチ ファイルを用意しました。

@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

ネットSh救助へ!

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

関連情報