From eb55683c2e6b5fe1eb7635062b3f1b85b571b6f7 Mon Sep 17 00:00:00 2001 From: "Satur@it-depot.ru" Date: Mon, 10 Mar 2025 11:05:19 +0300 Subject: [PATCH] Scheduler --- RustInstall.ps1 | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/RustInstall.ps1 b/RustInstall.ps1 index be2b42e..21f2f8a 100644 --- a/RustInstall.ps1 +++ b/RustInstall.ps1 @@ -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 \ No newline at end of file