@echo off
:: === Self-elevate ===
net session >nul 2>&1
if %errorLevel% NEQ 0 (
    echo Requesting administrative privileges...
    powershell.exe -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
    exit
)

:: === Run PowerShell script with Bypass policy ===
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
"Write-Host '=== Creating scheduled task to restart RdpGuard ==='; ^
$time='04:00'; ^
Register-ScheduledTask -TaskName 'Restart RdpGuard' ^
    -Action (New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -WindowStyle Hidden -Command `"net stop RdpGuardProxy >`$null 2>&1; net start RdpGuardProxy >`$null 2>&1; net stop RdpGuardService >`$null 2>&1; net start RdpGuardService >`$null 2>&1`"') ^
    -Trigger (New-ScheduledTaskTrigger -Daily -At $time) ^
    -Principal (New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest) ^
    -Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable); ^
Write-Host 'Scheduled task created successfully. It will run daily at ' $time; ^
pause"
