netx/packaging/uninstall_delete_data.ps1
oliver 97393cd407 Release 0.4.5: installer DB wizard, credential key, lean offline Setup.
Choose bundled or external PostgreSQL in the Setup wizard with connection
validation; optional NETX_CREDENTIAL_SECRET_KEY; single desktop shortcut;
faster uninstall and tray startup for offline Windows packages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-07 14:44:40 +08:00

53 lines
1.5 KiB
PowerShell

param(
[string]$DataRoot = ""
)
# Post-uninstall optional data wipe with retries (handles briefly locked runtime logs).
$ErrorActionPreference = "Continue"
if (-not $DataRoot) {
$DataRoot = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) "NetX"
}
if (-not (Test-Path -LiteralPath $DataRoot)) {
Write-Host "==> Data root already gone: $DataRoot"
exit 0
}
Write-Host "==> Deleting data root: $DataRoot"
# Kill anything still holding files under data root.
Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -and ($_.CommandLine.IndexOf($DataRoot, [StringComparison]::OrdinalIgnoreCase) -ge 0)
} | ForEach-Object {
try { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } catch {}
try { & taskkill.exe /F /PID $_.ProcessId 2>$null | Out-Null } catch {}
}
$ok = $false
for ($i = 1; $i -le 5; $i++) {
try {
cmd /c "rmdir /s /q `"$DataRoot`""
} catch {}
if (-not (Test-Path -LiteralPath $DataRoot)) {
$ok = $true
break
}
Start-Sleep -Seconds 1
}
if (-not $ok -and (Test-Path -LiteralPath $DataRoot)) {
try {
takeown /F $DataRoot /R /D Y | Out-Null
icacls $DataRoot /grant Administrators:F /T | Out-Null
cmd /c "rmdir /s /q `"$DataRoot`""
} catch {}
}
if (Test-Path -LiteralPath $DataRoot) {
Write-Host "[WARN] Could not fully delete $DataRoot"
exit 1
}
Write-Host "==> Data root deleted"
exit 0