Managing Proxy Settings on Windows via Command Line
Managing proxy settings through the GUI is tedious, especially when you need to switch between multiple proxy servers frequently. Rather than hunting through settings menus each time, command-line tools eliminate friction and enable scripted deployments across your infrastructure.
The original SetProxy tool is outdated and incompatible with modern Windows versions. Use netsh or PowerShell instead—both are built-in with no compilation or installation required.
Setting WinHTTP Proxy with netsh
WinHTTP is the system-wide proxy layer used by most applications, including Edge, curl, and many CLI tools:
netsh winhttp set proxy proxy-server="http=192.168.1.100:8080;https=192.168.1.100:8080" bypass-list="localhost;127.0.0.1;<local>"
Breaking this down:
proxy-serveraccepts separate entries for HTTP and HTTPSbypass-listspecifies hosts that bypass the proxy<local>is a built-in token that matches any single-label hostname
View current settings:
netsh winhttp show proxy
Clear the proxy entirely:
netsh winhttp reset proxy
Per-User Registry Proxy (Legacy Applications)
Some older applications read proxy settings from the Registry instead of WinHTTP. This affects Internet Explorer and similar legacy tools:
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $regPath -Name ProxyServer -Value "192.168.1.100:8080"
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
Disable it:
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
If you need separate HTTP and HTTPS proxies, format them as a single value:
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $regPath -Name ProxyServer -Value "http=192.168.1.100:8080;https=192.168.1.100:8443"
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
Batch File Wrappers for Quick Access
Create reusable batch files to toggle proxies without opening a terminal.
proxy-enable.bat:
@echo off
netsh winhttp set proxy proxy-server="http=192.168.1.100:8080;https=192.168.1.100:8080" bypass-list="localhost;127.0.0.1;<local>"
echo Proxy enabled: 192.168.1.100:8080
pause
proxy-disable.bat:
@echo off
netsh winhttp reset proxy
echo Proxy disabled
pause
Save these to a folder on your PATH or create desktop shortcuts by right-clicking the batch file and selecting “Send to > Desktop (create shortcut)”. Double-click to apply settings instantly.
Automated Proxy Rotation
For environments requiring frequent proxy switches, rotate through a list randomly:
$proxies = @(
"proxy1.internal:8080",
"proxy2.internal:8080",
"proxy3.internal:8080"
)
$currentIndex = Get-Random -Minimum 0 -Maximum $proxies.Length
$proxy = $proxies[$currentIndex]
netsh winhttp set proxy proxy-server="http=$proxy;https=$proxy"
Write-Host "Proxy set to: $proxy"
For sequential rotation with state persistence, use a configuration file:
$configFile = "$env:TEMP\proxy-index.txt"
$lastIndex = if (Test-Path $configFile) { [int](Get-Content $configFile) } else { 0 }
$proxies = @(
"proxy1.internal:8080",
"proxy2.internal:8080",
"proxy3.internal:8080"
)
$nextIndex = ($lastIndex + 1) % $proxies.Length
$proxy = $proxies[$nextIndex]
netsh winhttp set proxy proxy-server="http=$proxy;https=$proxy"
$nextIndex | Set-Content $configFile
Write-Host "Proxy set to: $proxy (index $nextIndex)"
Applying Proxy to Scheduled Tasks
When running applications or scripts as a service account, WinHTTP proxy settings are tied to the user context. If your task runs as SYSTEM, configure WinHTTP for that account:
# Run as Administrator
# For SYSTEM context tasks, hardcode proxy in application config instead
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $regPath -Name ProxyServer -Value "192.168.1.100:8080"
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
Alternatively, hardcode the proxy in application configuration files or environment variables rather than relying on system-wide settings:
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://192.168.1.100:8080", "Machine")
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://192.168.1.100:8080", "Machine")
Verifying Proxy Configuration
Check what your system sees across different layers:
# WinHTTP proxy (system-wide)
netsh winhttp show proxy
# PowerShell's built-in proxy
$env:HTTP_PROXY
# Internet Explorer / Legacy apps (Registry)
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
# Machine-level environment variables
[Environment]::GetEnvironmentVariable("HTTP_PROXY", "Machine")
Note that different components may use different proxy configurations. Applications that use WinHTTP see netsh winhttp settings, while older apps may only respect Registry settings. Language runtimes (Python, Node.js) typically respect HTTP_PROXY and HTTPS_PROXY environment variables.
SOCKS Proxy Support
WinHTTP does not natively support SOCKS proxies. If you need SOCKS, use one of these approaches:
- Configure applications individually (
curlvia--socks5,sshviaProxyCommand) - Use a local HTTP-to-SOCKS converter like Privoxy or Tinyproxy
- Set environment variables for language-specific tools (Python, Node.js, Go, Rust) that understand SOCKS natively
Example with Python:
set HTTPS_PROXY=socks5://localhost:1080
python script.py
For persistent SOCKS support on Windows, consider running a local HTTP proxy that translates to SOCKS:
# Install Privoxy, configure with SOCKS parent
# Edit privoxy config to forward to SOCKS5
listen-address 127.0.0.1:8118
forward-socks5 / localhost:1080 .
Then configure WinHTTP to use the local proxy:
netsh winhttp set proxy proxy-server="http=127.0.0.1:8118;https=127.0.0.1:8118"

小强,这个编译不过去啊….Windows7 x64, Visual Studio 2012
Sorry, no Chinese input method installed…
Try to make this change to the SetProxy.cpp:
Change
#include <iostream.h>to
#include <iostream>using namespace std;
The new compiler from MS Visual Studio seems have obsoleted the “<iostream.h>” like headers.
BTW: this is a plain old piece of code which is written on Windows XP. I am surprised that someone like you tried it. I am surprised again that this piece of code is still working on Windows 7 after I tried it. Good backwards compatibility, MS!
BTW: Sorry, but who are you? Collage classmate? You are using Visual studio and have interests on command line tools on Windows. There are not many people like this around there except CS students/graduates.
你说的这俩地方我在看到代码时候就已经改了,可是还是编不过去啊….我Li Yiji…..这两天Evernote同步总是失败,这东西不能自己设代理,又觉得手动改ie代理太麻烦,所以上网搜了一下,然后就搜到你这里了
哦, 原来是你 ;) 当初在复旦也是觉得改代理麻烦, 写了这个小程序.
咦,你是不是更新了源码的下载链接…我记得以前下载的只有个SetProxy.cpp啊…..这回刚下载的能编译过去了…..
链接没有动. 还是原来那份一直没动. 我在Windows 7上试了下, 还是好用 ;) 你以前是不是解压后直接把SetProxy.cpp打开了?
我直接用VS新建了一个项目然后添加了SetProxy.cpp……
里面还有一个WININET.H文件, 不在系统头文件目录中的. 你把这个文件也添加进去应该可行.
我在系统里找到了WinInet.h这个文件啊….windows是大小写不敏感的吧,我记得
这个我就不太知道问题可能在那里了. 你diff下看这个有没有些特殊代码在里面. 另外比较一下编译器在这个project里面的参数设置看有没有特殊的地方. 我当初些这个程序时应该是在32位系统下的.
Thank you very much!
This really helped because setting the proxy by command line using the registry keys requires the user to open the window “LAN settings” and closing to wake up browsers about the change.
However, your software really overcomes this problem!