How can I change the system proxy from the command line?

3

1

I have to connect to my university proxy if I have to access the internet and my university has two proxies.

Now at times on of em gets inundated with traffic so we switch to the other proxy, now I was wondering if I could write a batch script or a python file and assign it a keyboard shortcut so the switch would be fast!

Aditya

Posted 2014-01-30T12:26:08.787

Reputation: 144

Why is this tagged both "windows-7" and "ms-dos"? Windows 7 doesn't use MS DOS. – Ignacio Vazquez-Abrams – 2014-01-30T12:49:36.460

@IgnacioVazquez-Abrams I think it is clear that he meant command line / batch script rather than actual ms-dos. But the question should indeed be corrected, as it now has been :) – zelanix – 2014-01-30T12:53:31.193

@zelanix: If someone doesn't call them out on it then they'll never learn. – Ignacio Vazquez-Abrams – 2014-01-30T13:11:00.707

Answers

4

You should be able to set the proxy with netsh:

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="*.foo.com"

Those are the examples from netsh winhttp set proxy help. The WinHTTP proxy settings aren't used by all applications. It's probably best to use the solution outlined in zelanix answer and then just import the IE settings into WinHTTP with:

netsh winhttp import proxy source=ie

Der Hochstapler

Posted 2014-01-30T12:26:08.787

Reputation: 77 228

What does that 88 means in https=sproxy:88"? And what is the correct format for myproxy and sproxy? Should I replace myproxy with 127.0.0.1:8080 and sproxy with 127.0.0.1:8090 for example? – Abraham – 2015-10-07T07:22:09.103

2@Abraham: 88 is the port on which the proxy for HTTPS connections can be reached. Your examples look correct to me. I also added a link to the official netsh documentation for this command to my answer. Hope it helps :) – Der Hochstapler – 2015-10-07T07:28:35.007

Proxy configuration in Windows is a nightmare! Probably winhttp is the way to go, though. – zelanix – 2014-01-30T13:06:42.977

4

Proxy configuration is tricky becuse it is often configured in each application separately. However, many application use the Internet Explorer settings as the default and they can be set through the registry as detailed here (Microsoft Support). You could create a .reg file for each proxy and either double click it to apply the settings or create a simple batch script to import it.

The registry file has the following form:

Regedit4

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"MigrateProxy"=dword:00000001
"ProxyEnable"=dword:00000001
"ProxyHttp1.1"=dword:00000000
"ProxyServer"="http://ProxyServername:80"
"ProxyOverride"="<local>"

Alternatively configure each proxy in turn and then browse to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings and export the relevant settings.

This configuration could of course also be wrapped up in anything else (VBScript or whatever) that is capable of writing to the registry.

zelanix

Posted 2014-01-30T12:26:08.787

Reputation: 1 134

0

The system proxy server can be modified using the netsh command in Windows 7.

Adam Tauno Williams

Posted 2014-01-30T12:26:08.787

Reputation: 1