The problem was simple, infuriatingly so: the cleanup script—a humble cleanup_logs.bat —needed admin rights to delete the old system logs. But the scheduled task kept running it under the SYSTEM account with limited token privileges, and the junior admin who set it up was long gone.
The script was demanding interactive consent. On a headless server.
Alan sipped his cold coffee. "The batch file… promoted itself."
@echo off net session >nul 2>&1 if %errorlevel% neq 0 ( echo Requesting administrator privileges... powershell start -verb runas '%0' exit /b ) He saved it. Double-clicked.
He opened Notepad and loaded the batch file. At the very top, above the del commands and the rmdir sweeps, he typed:
Alan stared at the blinking cursor on his screen. It was 11:47 PM. The server migration was supposed to be done by 9.
schtasks /create /tn "AdminElevate_%random%" /tr "%~dp0cleanup_logs.bat" /sc once /st 00:05 /rl highest /f schtasks /run /tn "AdminElevate_%random%" It worked. The task spawned, elevated silently, ran the script, and self-deleted.
He remoted in. The UAC prompt was there, waiting. But no one was logged in to click "Yes."