Files
openclaw-setup-cn/uninstall-windows.ps1

67 lines
2.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ─────────────────────────────────────────────
# OpenClaw 卸载脚本 (Windows)
# 与当前“原生 Windows 安装”流程对齐
# ─────────────────────────────────────────────
$ErrorActionPreference = "Stop"
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; throw $msg }
Write-Host ""
Write-Host "========================================" -ForegroundColor White
Write-Host " OpenClaw 卸载器 (Windows)" -ForegroundColor White
Write-Host "========================================" -ForegroundColor White
Write-Host ""
$uninstalled = $false
# 1) 优先使用已安装的 openclaw 命令
if (Get-Command openclaw -ErrorAction SilentlyContinue) {
try {
Write-Info "已找到 openclaw正在卸载--all..."
openclaw uninstall --all --yes --non-interactive
$uninstalled = $true
Write-Ok "OpenClaw 卸载命令执行完成。"
} catch {
Write-Warn "openclaw 卸载失败,尝试 npx 方式..."
}
}
# 2) 回退npx 直接调用
if (-not $uninstalled) {
if (Get-Command npx -ErrorAction SilentlyContinue) {
try {
Write-Info "使用 npx 执行卸载..."
npx -y openclaw uninstall --all --yes --non-interactive
$uninstalled = $true
Write-Ok "OpenClaw 卸载命令执行完成npx"
} catch {
Write-Warn "npx 卸载失败。"
}
} else {
Write-Warn "未找到 npx跳过 npx 卸载。"
}
}
# 3) 清理全局 npm 包(幂等,失败不终止)
if (Get-Command npm -ErrorAction SilentlyContinue) {
try {
Write-Info "尝试移除全局 npm 包 openclaw如存在..."
npm uninstall -g openclaw 2>$null | Out-Null
Write-Ok "全局 npm 包清理完成。"
} catch {
Write-Warn "全局 npm 包清理跳过:$_"
}
}
if (-not $uninstalled) {
Write-Err "未能完成 OpenClaw 卸载。请确认 Node.js/npm 可用后重试。"
}
Write-Host ""
Write-Ok "OpenClaw 已卸载。"
Write-Host ""