-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstall-PythonGuardian.ps1
More file actions
29 lines (27 loc) · 1.5 KB
/
Copy pathUninstall-PythonGuardian.ps1
File metadata and controls
29 lines (27 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<# Remove Python Guardian while retaining user crash evidence. #>
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$installRoot = [System.IO.Path]::GetFullPath($PSScriptRoot)
$marker = Join-Path $installRoot '.python-guardian-install'
if (-not (Test-Path -LiteralPath $marker -PathType Leaf) -or
(Get-Content -Raw -LiteralPath $marker).Trim() -ne 'PythonGuardian 0.1.0') {
throw "Refusing to uninstall: installation marker is missing from $installRoot"
}
$runtimePython = Join-Path $installRoot 'guardian_venv\Scripts\python.exe'
$control = Join-Path $installRoot 'guardian_ctl.py'
if (Test-Path -LiteralPath $runtimePython -PathType Leaf) {
try { & $runtimePython $control stop | Out-Null } catch { }
}
& (Join-Path $installRoot 'Install-PythonFileLauncher.ps1') -Uninstall
Remove-Item -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\PythonGuardian' `
-Recurse -Force -ErrorAction SilentlyContinue
$cleanup = Join-Path $env:TEMP ("Remove-PythonGuardianFiles-{0}.ps1" -f [guid]::NewGuid())
Copy-Item -LiteralPath (Join-Path $installRoot 'Remove-PythonGuardianFiles.ps1') `
-Destination $cleanup -Force
Start-Process -FilePath 'powershell.exe' -WindowStyle Hidden -ArgumentList @(
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $cleanup, '-InstallRoot', $installRoot
)
Write-Output 'Python Guardian was unregistered. Program files will be removed momentarily.'
Write-Output 'Crash evidence under %LOCALAPPDATA%\PythonGuardian was retained.'