In Windows 7, how to change proxy settings from command line?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 In Windows 7, How To Change Proxy Settings From Command Line?
00:22 Accepted Answer Score 16
01:40 Answer 2 Score 28
02:08 Answer 3 Score 63
02:46 Answer 4 Score 2
03:06 Thank you
--
Full question
https://superuser.com/questions/419696/i...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows7 #windows #proxy #batchfile
#avk47
ANSWER 1
Score 63
Simple and working solution retrieved from http://www.ehow.com/how_6887864_do-proxy-settings-command-prompt_.html
Command to enable proxy usage:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 1 /f
Command to disable proxy usage:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyEnable /t REG_DWORD /d 0 /f
Command to change the proxy address:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
/v ProxyServer /t REG_SZ /d proxyserveraddress:proxyport /f
I have added line continuation (^) for improved readability. Also, in this case, it is more like a per-user setting than a system-wide setting.
ANSWER 2
Score 28
NetSh to the rescue!
NetSh winhttp set proxy
should be helpful. Here are the commands:
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"
ACCEPTED ANSWER
Score 16
You'll need to configure a registry script that will make the changes you normally would via the Control Panel, and then merge the script to enable the proxy. You would also need an "undo" registry script to disable the changes.
In my case, I have two scripts, enable.reg and disable.reg:
Enable Proxy:
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
Disable Proxy:
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
In the "disable" script, the =-
at the end of AutoConfigURL actually deletes the key from the registry.
Note that the values you see above are modified for the purposes of this answer. The actual hex values are much longer.
To use these scripts, I had a batch file for each one, looking something like this:
@echo off
start /min reg import C:\Path\To\Registry\File\enable_proxy.reg
That is fully workable from the command line.
ANSWER 4
Score 2
Create a batch file and paste following content(It will toggle the Proxy state),
@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