# ============================================================================= # LOI Monitrack Windows Agent - 완전 제거 스크립트 (관리자 권한) # # - MSI 설치본: msiexec /x 로 제거(서비스·파일·폴더까지 정리) # - 구버전(exe) 설치본: 서비스 삭제 후 폴더 정리 # - 마지막에 C:\LoiAgent 폴더까지 삭제 ( -KeepFolder 로 보존 가능 ) # # 사용법 (관리자 PowerShell): # powershell -ExecutionPolicy Bypass -File uninstall_agent.ps1 # powershell -ExecutionPolicy Bypass -File uninstall_agent.ps1 -KeepFolder # ============================================================================= [CmdletBinding()] param( [string] $AgentDir = "C:\LoiAgent", [switch] $KeepFolder ) $ErrorActionPreference = 'Continue' function Step($t){ Write-Host ("[*] " + $t) -ForegroundColor Cyan } function Ok($t){ Write-Host (" [OK] " + $t) -ForegroundColor Green } function Warn($t){ Write-Host (" [!] " + $t) -ForegroundColor Yellow } Write-Host "===== LOI Monitrack Agent 제거 =====" -ForegroundColor White if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw "관리자 권한으로 실행하세요." } # 1) MSI 제품이 있으면 msiexec /x 로 제거 Step "MSI 제품 확인/제거" $prod = $null foreach ($root in "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall") { $prod = Get-ChildItem $root -ErrorAction SilentlyContinue | ForEach-Object { Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue } | Where-Object { $_.DisplayName -eq 'LOI Monitrack Agent' } | Select-Object -First 1 if ($prod) { break } } if ($prod) { $code = $prod.PSChildName Ok ("MSI 제거: {0} (v{1})" -f $code, $prod.DisplayVersion) $p = Start-Process msiexec.exe -ArgumentList "/x $code /qn /norestart" -Wait -PassThru Ok ("msiexec 종료코드: {0}" -f $p.ExitCode) } else { Warn "MSI 제품이 없습니다 (구버전 exe 설치일 수 있음)" } # 2) 구버전(비MSI) 잔여 서비스 정리 Step "레거시 서비스 정리(있으면)" if (Get-Service LOI_Zabbix -ErrorAction SilentlyContinue) { Stop-Service LOI_Zabbix -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 1 sc.exe delete LOI_Zabbix | Out-Null Ok "서비스 LOI_Zabbix 삭제" } else { Ok "잔여 서비스 없음" } # 3) 폴더까지 삭제 (요청 시 보존) if ($KeepFolder) { Warn ("폴더 보존: {0}" -f $AgentDir) } else { Step ("폴더 삭제: {0}" -f $AgentDir) if (Test-Path $AgentDir) { Remove-Item $AgentDir -Recurse -Force -ErrorAction SilentlyContinue } Ok ("폴더 존재: {0}" -f (Test-Path $AgentDir)) } Write-Host "===== DONE (완료) =====" -ForegroundColor White