@echo off
title WINGI Print Agent - uninstall
echo.
echo  Removing the WINGI print agent from this PC...

rem 1) disable auto-start (scheduled task + old startup shortcut)
schtasks /delete /tn "WINGI Print Agent" /f >nul 2>nul
del "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\WINGI Print Agent.lnk" >nul 2>nul

rem 2) stop the background loop + the agent (precise: never kills this script)
powershell -NoProfile -Command "$me=$PID; Get-CimInstance Win32_Process | Where-Object { $_.ProcessId -ne $me -and $_.CommandLine -match 'run-hidden\.vbs|wingi-agent\.exe|run-agent\.bat run' } | ForEach-Object { try{ Stop-Process -Id $_.ProcessId -Force }catch{} }" >nul 2>nul
taskkill /f /im wingi-agent.exe >nul 2>nul

rem 3) optionally delete the agent files that sit next to this uninstaller
del "%~dp0wingi-agent.exe"  >nul 2>nul
del "%~dp0wingi-agent.json" >nul 2>nul
del "%~dp0run-hidden.vbs"   >nul 2>nul
del "%~dp0wingi-agent.exe.new" >nul 2>nul

echo.
echo  ============================================
echo   Done. The agent is stopped, auto-start is
echo   removed, and its files were deleted.
echo  ============================================
echo.
pause
