49

How do I change proxy settings from command line in Windows 7?

I'm not talking about just the http_proxy. I need to set system-wide proxy settings (the ones in Internet properties setting). How do I do that?

1

7 Answers 7

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.

3
  • I ended up doing something like this. I didn't know how to manipulate registry from batch script so I wrote c# code for this.. :). thanx anyways..
    – prongs
    Commented May 3, 2012 at 10:41
  • This does not seem to work for me. Should I actually see the "use automatic configuration script" box being ticked and unticked in 'LAN Settings'?
    – Jonny
    Commented Feb 1, 2015 at 10:39
  • @prongs I doubt you're going to share that C# code... right? Commented Mar 18, 2018 at 0:26
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.

7
  • 3
    IMO, this is the actual answer to the question. Thanks @sayap
    – kmonsoor
    Commented Dec 26, 2012 at 4:21
  • 4
    +1. This is a much more elegant solution to mine.
    – user3463
    Commented Jul 29, 2013 at 20:28
  • 3
    Note: The ^ characters are not part of the commands. Commented Oct 10, 2013 at 19:40
  • 7
    But browsers don't navigate until you open the "LAN configuration" window. At least this happens to me when I use this method. I do this to wake up browsers that the proxy changed, only after that, the connecion works. Commented Aug 19, 2015 at 18:11
  • 1
    @Cricrazy this is what you were looking for I think
    – Narzard
    Commented Jul 7, 2016 at 15:23
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"

2
  • 1
    Clearing the proxy using netsh: netsh winhttp reset proxy Commented Aug 15, 2012 at 19:15
  • 9
    I think this only applies to application that uses the WinHTTP library. After a quick test, it doesn't seem like any common application on my system uses that.
    – sayap
    Commented Aug 29, 2012 at 11:01
5

I did it in C#, but the philosphy is the same, writing to the registry, so the following instructions can be extrapolated to line command. It shall be done three things:

  1. Write to Registry "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings", on ProxyEnable: 1 to enable, 0 to disable

  2. Write to Registry "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings", on ProxyServer: xxx.xxx.xxx.xxxx:yyyy (xxx... is the IP, yy.. is the port)

  3. After performing steps 1 and 2 you will have written to registry the activation of proxy and the IP and port, but if you open the browser you will notice that it is not enough, you can't navigate yet. The third step consists of changing the registry regarding connections settings:

"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" on "DefaultConnectionSettings".

Notice that although (at least for W7) there are 204 bytes in this registry, you only have to modify byte 8 (9th since byte 0 is the first). Byte 8 value not only contains information about proxy enable/disable, but also about other functionalities:

        //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. 

In my case, the 'Automatically detect settings' is always enabled, so I switch the value of byte 8 from 09 to 0B and viceversa to enable and disable the proxy.

1
  • 2
    I found an answer on SO that updates the DefaultConnectionSettings setting using powershell. I thought it may be useful for somebody. stackoverflow.com/a/15914470/1158180
    – paulH
    Commented Dec 5, 2018 at 11:23
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
1
  • 1
    This is very similar to @sayap's answer.
    – user3463
    Commented Jul 29, 2013 at 20:29
1

This script may do it:

REM Enable-Disable System Proxy in one file
@echo off
SET home_key="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
FOR /F "tokens=3" %%L IN ('reg query %home_key% /v ProxyEnable' ) DO SET currentProxy=%%L
IF %currentProxy% == 0x1 goto turnoff
IF %currentProxy% == 0x0 goto turnon

:turnoff
reg add %home_key% /v ProxyEnable /t REG_DWORD /d 0 /f
SET proxy="Proxy disabled"
goto EOF

:turnon
reg add %home_key% /v ProxyEnable /t REG_DWORD /d 1 /f
SET proxy="Proxy enabled"
goto EOF

:EOF
REM Restart Internet Explorer to changes take efect
start /w /b iexplore.exe
timeout 2 /nobreak
taskkill /f /im iexplore.exe
echo %proxy%
-3

I hope I am pointing you in the correct direction here, but if you are trying to access the proxy settings through "Internet options", simply open the start menu and type "internet option" (any setting or application you can locate this way also example "proxy"). You should then recognize this menu and be able to add your needed settings.

2
  • 1
    dude... you didn't see the title proprely... I know what you are trying to tell me. I want to do it from command line.
    – prongs
    Commented May 2, 2012 at 16:24
  • sorry man, seems like buddy got you all fixed up though Commented May 2, 2012 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .