# 天翼云: 补 frpc.toml 的 glances 隧道段 + 重启 frpc + 起 glances $ErrorActionPreference='Continue' $toml = (Get-ChildItem 'C:\frp' -Recurse -Filter frpc.toml -ErrorAction SilentlyContinue | Select-Object -First 1).FullName if (-not $toml) { Write-Host 'FAIL: 找不到 frpc.toml'; return } Write-Host (">>> toml: " + $toml) $c = Get-Content $toml -Raw if ($c -notmatch 'name = "glances"') { Add-Content -Path $toml -Value @('','[[proxies]]','name = "glances"','type = "tcp"','localIP = "127.0.0.1"','localPort = 61208','remotePort = 61209') Write-Host '>>> 已追加 glances 隧道段' } else { Write-Host '>>> glances 段已存在,跳过' } Write-Host '>>> 重启 frpc...' Get-Process frpc -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep 1 try { Start-ScheduledTask -TaskName frpc -ErrorAction Stop; Start-Sleep 4 } catch {} if (-not (Get-Process frpc -ErrorAction SilentlyContinue)) { $exe = (Get-ChildItem 'C:\frp' -Recurse -Filter frpc.exe | Select-Object -First 1).FullName Start-Process -WindowStyle Hidden $exe -ArgumentList '-c',$toml; Start-Sleep 4 } Write-Host '>>> 起 glances...' $py='C:\Python314\python.exe' Set-Content -Path 'C:\glances.bat' -Value ($py + ' -m glances -w -t 5 > C:\glances.log 2>&1') -Encoding Ascii schtasks /create /tn glances /tr C:\glances.bat /sc onstart /ru SYSTEM /rl HIGHEST /f | Out-Null Get-CimInstance Win32_Process -Filter "name='python.exe'" -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like '*glances*' } | ForEach-Object { Invoke-CimMethod -InputObject $_ -MethodName Terminate | Out-Null } Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{CommandLine='cmd /c C:\glances.bat'} | Out-Null Start-Sleep 8 Write-Host ('frpc 运行: ' + [bool](Get-Process frpc -ErrorAction SilentlyContinue)) Write-Host ('glances 61208: ' + (Test-NetConnection 127.0.0.1 -Port 61208 -WarningAction SilentlyContinue).TcpTestSucceeded) Write-Host '=== DONE ==='