#Requires -Version 5.1 #Requires -RunAsAdministrator $ErrorActionPreference = 'Stop' $programFiles = $env:ProgramW6432 if (-not $programFiles) { $programFiles = $env:ProgramFiles } $cli = Join-Path $programFiles 'WangYunLian CLI' if ((Test-Path -LiteralPath $cli) -and ((Get-Item -LiteralPath $cli).Attributes -band [IO.FileAttributes]::ReparsePoint)) { throw '安装目录是链接,请核对真实目录后按手动教程处理。' } $agent = Join-Path $cli 'wangyunlian-agent.exe' foreach ($name in @('WangYunLianAgent', 'OneVPNAgent')) { $service = Get-CimInstance Win32_Service -Filter "Name='$name'" if ($service -and $service.PathName.Trim('"') -eq $agent) { Stop-Service -Name $name -ErrorAction Stop (Get-Service $name).WaitForStatus('Stopped', [TimeSpan]::FromSeconds(30)) & sc.exe delete $name if ($LASTEXITCODE -ne 0) { throw '服务未删除,请先处理错误再继续。' } } elseif ($service) { Write-Host ('保留其他安装提供的共享服务:' + $name) } } $rule = Get-NetFirewallRule -Name 'WangYunLianCLI-Agent-UDP' -ErrorAction SilentlyContinue if ($rule) { $application = $rule | Get-NetFirewallApplicationFilter if ($application.Program -ne $agent) { throw '防火墙规则的程序路径不匹配,请人工核对。' } $rule | Remove-NetFirewallRule } $machinePath = [Environment]::GetEnvironmentVariable('Path', 'Machine') $newPath = ($machinePath -split ';' | Where-Object { $_.TrimEnd('\') -ne $cli.TrimEnd('\') }) -join ';' [Environment]::SetEnvironmentVariable('Path', $newPath, 'Machine') foreach ($file in @('wangyunlian.exe', 'wangyunlian-agent.exe', 'wintun.dll', 'WINTUN-LICENSE.txt', 'uninstall.ps1')) { $path = Join-Path $cli $file if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -ErrorAction Stop } } if ((Test-Path -LiteralPath $cli) -and -not (Get-ChildItem -LiteralPath $cli -Force)) { Remove-Item -LiteralPath $cli } Write-Host '网云连命令行版已移除,账号、设备身份和配置已保留。请新开终端。' Write-Host '不再使用的设备请在控制台逐网移除:https://wangyunlian.com/console/'