Windows 中的几种原生网络代理方式

IE / 用户代理(WinINET)

这就是在系统中直接设置的代理,或者是 Internet 选项中设置的代理。设置很容易,可以给 浏览器 实现网络代理,同时也能用于 检查系统更新office 安装teamsOutlook

同时支持 pac 模式,进行简单的分流。分流规则是要么使用代理,要么直连。

代理跟着用户走,不影响已登录的其他用户

注意,由于这种代理跟着用户走,而部分程序比如 office 安装程序需要管理员权限才能运行,而有些情况下登录的账户不是管理员账户。所以需要对管理员账户设置代理,然后使用该管理员账户运行程序。

# 配置代理
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 ProxyServer /t REG_SZ /d "http=10.72.64.178:8080;https=10.72.64.178:8080" /f

# 还原
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /f

# 或者使用 PAC 代理
$pacUrl = "http://10.72.64.178:8082/msupdate.pac"
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "AutoConfigURL" -Value $pacUrl
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyEnable" -Value 0
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | Select-Object AutoConfigURL, ProxyEnable

# 还原
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "AutoConfigURL" -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "ProxyEnable" -Value 0

系统范围代理(WinHTTP)

比 IE/用户代理更底层的一种方式,这种方案可以给系统级进程做代理,比如使用了 WinHTTP 的 Windows 安装助手

使用管理员身份进行设置:

netsh winhttp set proxy http://your-proxy-server:port

验证是否生效:

netsh winhttp show proxy

不再需要代理后恢复默认:

netsh winhttp reset proxy

全局代理,影响所有用户。

第三方代理软件

Clash, Shadowrocket 等等就不做记录了。

Comments