You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过命令行或PowerShell开启并配置Windows代理?

命令行/PowerShell配置Windows代理的正确方法

一、手动代理配置(开启「使用代理服务器」)

之前的注册表修改仅设置了基础项,且未通知系统刷新配置,导致界面显示未生效。正确操作步骤如下:

  1. 配置代理地址与启用状态
# 设置代理服务器地址
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d "10.0.0.6:8080" /f
# 启用手动代理
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 ProxyOverride /t REG_SZ /d "*.internal.com;localhost;127.0.0.1" /f
  1. 强制系统刷新代理配置
    修改注册表后,必须通知系统更新设置,避免界面显示滞后:
$signature = @"
[DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
"@
$type = Add-Type -MemberDefinition $signature -Name InternetSetOption -Namespace Win32 -PassThru
$type::InternetSetOption([IntPtr]::Zero, 39, [IntPtr]::Zero, 0) | Out-Null
$type::InternetSetOption([IntPtr]::Zero, 37, [IntPtr]::Zero, 0) | Out-Null

注意:netsh winhttp set proxy 配置的是系统级代理(供Windows服务、后台程序使用),而非浏览器/普通应用显示的用户级代理,修改后不会在设置界面体现,仅对特定场景生效。

二、自动脚本代理配置(开启「使用设置脚本」)

自动代理脚本与手动代理互斥,需配置脚本地址并关闭手动代理:

# 设置自动代理脚本地址
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "http://your-proxy-script-url/proxy.pac" /f
# 关闭手动代理
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
# (可选)启用自动代理发现
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v EnableAutoProxyDiscovery /t REG_DWORD /d 1 /f

执行上述的InternetSetOption代码刷新系统配置,确保界面同步生效。

验证配置生效

  • 打开Windows设置 → 网络和互联网 → 代理,查看界面状态是否更新
  • 在PowerShell中执行以下命令查看用户级代理详情:
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | Select-Object ProxyServer, ProxyEnable, AutoConfigURL

内容的提问来源于stack exchange,提问作者Joy Ho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 17:33:18