Scheduler

main
Satur@it-depot.ru 2025-03-10 11:05:19 +03:00
parent 2bed020336
commit eb55683c2e
1 changed files with 47 additions and 1 deletions

View File

@ -224,7 +224,7 @@ $RustID = $rustdesk_id
$ComputerName = $env:COMPUTERNAME
$InstallTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$ServerURL = "http://rust.it-depot.ru:8002/api/install"
$ServerURL = "https://rd.it-depot.ru/api/install"
$Body = @{
"rust_id" = $RustID
"computer_name" = $ComputerName
@ -232,8 +232,54 @@ $Body = @{
} | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $ServerURL -Method Post -Body $Body -ContentType "application/json"
echo "Initial entry added to address book."
echo "..............................................."
echo ""
# Создание отдельного скрипта для проверки онлайн-статуса
$checkScriptPath = "C:\ProgramData\RustDesk\RustDeskOnlineCheck.ps1"
$checkScriptContent = @"
`$ErrorActionPreference = 'SilentlyContinue'
`$RustID = "$RustID"
`$ComputerName = "$ComputerName"
`$InstallTime = "$InstallTime"
`$ServerURL = "https://rd.it-depot.ru/api/install"
while (`$true) {
`$Body = @{
`"rust_id`" = `$RustID
`"computer_name`" = `$ComputerName
`"install_time`" = `$InstallTime
`"last_seen`" = (Get-Date -Format `"yyyy-MM-dd HH:mm:ss`")
} | ConvertTo-Json -Compress
try {
Invoke-RestMethod -Uri `$ServerURL -Method Post -Body `$Body -ContentType `"application/json`" -ErrorAction Stop
Write-Host "Online ping sent for ID `$RustID at `(Get-Date -Format 'HH:mm:ss')" -ForegroundColor Green
}
catch {
Write-Host "Error sending online ping: `$_" -ForegroundColor Red
}
Start-Sleep -Seconds 30
}
"@
$checkScriptContent | Out-File -FilePath $checkScriptPath -Encoding UTF8
echo "Created online check script at $checkScriptPath"
# Создание задания в Планировщике задач
$taskName = "RustDeskOnlineCheck"
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$checkScriptPath`""
$trigger = New-ScheduledTaskTrigger -AtStartup # Запуск при старте системы
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable
$trigger.Repetition = New-ScheduledTaskTriggerRepetition -Interval (New-TimeSpan -Seconds 30) # Интервал 30 секунд
# Регистрация задания
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -User "SYSTEM" -RunLevel Highest -Force
echo "Scheduled task '$taskName' created to check online status every 30 seconds at system startup."
# Немедленный запуск задания
Start-ScheduledTask -TaskName $taskName
echo "Scheduled task '$taskName' has been started."
echo "Press Enter to open RustDesk."
pause
.\rustdesk.exe