桌面端的ChatGPT不走代理如何设置

languang666 2026-07-30 17:01 1



回环这都开了,不想开tun还有啥办法

最新回复 (12)
  • dreamslave 07-30 17:02
    1

    保存为.bat运行


    @echo off
    setlocal
    set "CHATGPT_PROXY_LAUNCHER=%~f0"
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$env:CHATGPT_PROXY_LAUNCHER='%CHATGPT_PROXY_LAUNCHER%'; $code=(Get-Content -LiteralPath $env:CHATGPT_PROXY_LAUNCHER | Select-Object -Skip 6) -join [Environment]::NewLine; Invoke-Expression $code"
    pause
    exit /b %ERRORLEVEL%

    $
    ErrorActionPreference = "Stop"

    #
    Change this if your Clash/Mihomo HTTP proxy uses a different port.
    $proxyHost = "127.0.0.1"
    $proxyPort = 7890
    $proxyHostPort = "${proxyHost}:$proxyPort"
    $proxyUrl = "http://$proxyHostPort"

    function Test-IsAdmin {
    $principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
    return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    }

    function Get-OpenAIAppPackage {
    # Prefer the merged ChatGPT desktop app. Keep the former Codex package as a
    # fallback while Microsoft Store updates are still rolling out.
    $packages = @(Get-AppxPackage -ErrorAction SilentlyContinue | Where-Object {
    $_.Name -like "OpenAI*ChatGPT*" -or
    $_.PackageFamilyName -like "OpenAI*ChatGPT*" -or
    $_.Name -like "OpenAI*Codex*" -or
    $_.PackageFamilyName -like "OpenAI*Codex*"
    })

    if (-not $packages) {
    throw "ChatGPT desktop app was not found. Install or update ChatGPT from Microsoft Store first."
    }

    return $packages |
    Sort-Object `
    @{ Expression = { if ($_.Name -match "ChatGPT") { 0 } else { 1 } } }, `
    @{ Expression = { [version]$_.Version }; Descending = $true } |
    Select-Object -First 1
    }

    function Get-OpenAIAppExecutable([object]$Package) {
    $knownRelativePaths = @(
    "app\ChatGPT.exe",
    "ChatGPT.exe",
    "app\Codex.exe",
    "Codex.exe"
    )

    foreach ($relativePath in $knownRelativePaths) {
    $candidate = Join-Path $Package.InstallLocation $relativePath
    if (Test-Path -LiteralPath $candidate) {
    return $candidate
    }
    }

    try {
    $manifest = Get-AppxPackageManifest -Package $Package.PackageFullName
    $applications = @($manifest.Package.Applications.Application)

    $application = $applications |
    Where-Object { [string]$_.Executable -match "(ChatGPT|Codex)\.exe$" } |
    Select-Object -First 1

    if (-not $application) {
    $application = $applications |
    Where-Object { -not [string]::IsNullOrWhiteSpace([string]$_.Executable) } |
    Select-Object -First 1
    }

    if ($application) {
    $candidate = Join-Path $Package.InstallLocation ([string]$application.Executable)
    if (Test-Path -LiteralPath $candidate) {
    return $candidate
    }
    }
    }
    catch {
    Write-Warning "Could not read the AppX manifest: $($_.Exception.Message)"
    }

    $candidate = Get-ChildItem -LiteralPath $Package.InstallLocation -Recurse -File -ErrorAction SilentlyContinue |
    Where-Object { $_.Name -in @("ChatGPT.exe", "Codex.exe") } |
    Sort-Object @{ Expression = { if ($_.Name -eq "ChatGPT.exe") { 0 } else { 1 } } }, FullName |
    Select-Object -First 1

    if ($candidate) {
    return $candidate.FullName
    }

    throw "Could not locate ChatGPT.exe in $($Package.InstallLocation)"
    }

    function Test-AppLoopback([string]$PackageFamilyName) {
    $loopbackList = (& CheckNetIsolation LoopbackExempt -s 2>$null | Out-String).ToLowerInvariant()
    return $loopbackList.Contains($PackageFamilyName.ToLowerInvariant())
    }

    function Add-AppLoopback([string]$PackageFamilyName) {
    Write-Host "Adding loopback exemption for $PackageFamilyName ..."
    & CheckNetIsolation LoopbackExempt -a -n="$PackageFamilyName" | Out-Host
    }

    function Invoke-ElevatedLoopback([string]$PackageFamilyName) {
    $safePackageFamilyName = $PackageFamilyName.Replace("'", "''")
    $elevatedCode = @"
    `$ErrorActionPreference = 'Stop'
    `$packageFamilyName = '$safePackageFamilyName'
    & CheckNetIsolation LoopbackExempt -a -n="`$packageFamilyName" | Out-Host
    Write-Host 'Loopback exemption added.'
    Start-Sleep -Seconds 2
    "@

    $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($elevatedCode))
    Start-Process -FilePath powershell.exe -Verb RunAs -Wait -ArgumentList @(
    "-NoProfile",
    "-ExecutionPolicy", "Bypass",
    "-EncodedCommand", $encoded
    )
    }

    Write-Host "ChatGPT-only proxy launcher"
    Write-Host "Proxy: $proxyUrl"
    Write-Host "Windows system proxy and permanent user environment variables will not be changed."
    Write-Host ""

    if (-not (Test-NetConnection $proxyHost -Port $proxyPort -InformationLevel Quiet)) {
    Write-Warning "$proxyHostPort is not reachable. Start Clash/Mihomo first, then run this file again."
    exit 1
    }

    $
    package = Get-OpenAIAppPackage
    $packageFamilyName = $package.PackageFamilyName
    $appExe = Get-OpenAIAppExecutable -Package $package

    Write-Host "Package: $($package.Name)"
    Write-Host "Version: $($package.Version)"
    Write-Host "Executable: $appExe"
    Write-Host ""

    if (-not (Test-AppLoopback -PackageFamilyName $packageFamilyName)) {
    if (Test-IsAdmin) {
    Add-AppLoopback -PackageFamilyName $packageFamilyName
    }
    else {
    Write-Host "Requesting administrator permission only to let ChatGPT access the local proxy ..."
    Invoke-ElevatedLoopback -PackageFamilyName $packageFamilyName
    }
    }

    if (-not (Test-AppLoopback -PackageFamilyName $packageFamilyName)) {
    Write-Warning "The loopback exemption is still not visible. If UAC was denied, run this file again and allow it."
    }

    $
    runningApp = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
    $_.ProcessName -match "^(ChatGPT|Codex)$"
    })

    if ($runningApp) {
    Write-Warning "ChatGPT/Codex is already running. Fully exit it first, then run this launcher again so the proxy settings are inherited."
    Write-Host "Continuing may cause Windows to reuse the existing process without the proxy settings."
    Write-Host ""
    }

    #
    These variables only affect the ChatGPT process tree launched by this file.
    $env:HTTP_PROXY = $proxyUrl
    $env:HTTPS_PROXY = $proxyUrl
    $env:ALL_PROXY = $proxyUrl
    $env:NO_PROXY = "localhost,127.0.0.1,::1"

    $
    arguments = @(
    "--proxy-server=$proxyUrl",
    "--proxy-bypass-list=localhost;127.0.0.1;::1;<local>"
    )

    Start-Process -FilePath $appExe -ArgumentList $arguments
    Write-Host "Started ChatGPT with process-local proxy $proxyUrl"

  • Bromden 07-30 17:03
    2

    咸鱼,proxifier

  • zzzbug 07-30 17:03
    3

    为啥不想开tun,tun不挺方便的吗

  • qwaz130258 07-30 17:04
    4

    直接虚拟网卡就行了,简单点

  • 废话多说-18cm 07-30 17:04
    5

    据说codex只能开tun

  • languang666 楼主 07-30 17:05
    6

    @zzzbug #3 @qwaz130258 #4 termius老是断开

  • 葱油拌面 07-30 17:07
    7

    啊?桌面端chatgpt不是electron 打包的吗,网页能代理就可以用,本身就不用tun

  • 霸总 07-30 17:08
    8

    proxifier最方便

  • tyqing 07-30 17:09
    9

    proxifiers是最优解

  • zlex 07-30 17:13
    10

    windows/mac 设置为系统代理即可。

  • lcy409 07-30 17:16
    11

    今天就处理过这个问题,之前在windows环境中加了代理设置,codex自动应用了 导致一直用不了,排查半天才发现这个


    也就是说 codex软件 会自动应用 环境设置中的代理设置

    "这个配置没有带协议(http:// 或 socks5://),导致 Codex Desktop 在建立 WebSocket 时解析代理失败,因此一直停留在提交状态。doctor 给出的报错:

    Proxy URL scheme not supported

    Codex Desktop:内部网络库会读取 HTTP_PROXY/http_proxy 环境变量,并且要求代理 URL 格式合法。当它读到:

    http_proxy=127.0.0.1:10808

    就无法解析为合法代理地址,于是 WebSocket 建立失败,任务一直无法真正发送。"

  • Fenger 07-30 17:42
    12

    路由器上怎么设置?用的是openwrt,折腾了一下全局模式都不行?但又不想用全局模式。

* 帖子来源NodeSeek
返回