diff --git a/Deploy-LoginMonitor.ps1 b/Deploy-LoginMonitor.ps1 index be83f3e..09c68e5 100644 --- a/Deploy-LoginMonitor.ps1 +++ b/Deploy-LoginMonitor.ps1 @@ -973,6 +973,26 @@ function Stop-RdpLoginMonitorMainProcesses { } } +function Test-RdpMonitorDeployTaskExecutionLimitUnlimitedValue { + param($Limit) + + if ($null -eq $Limit -or $Limit -isnot [TimeSpan]) { return $false } + if ($Limit.Ticks -le 0) { return $true } + if ($Limit.TotalDays -ge 999) { return $true } + return $false +} + +function Get-RdpMonitorDeployTaskExecutionTimeLimitLabelFromResolved { + param($Resolved) + + if ($null -eq $Resolved) { return '(null)' } + if ($Resolved.Source -eq 'missing') { return '(task missing)' } + $limit = $Resolved.Limit + if ($null -eq $limit) { return '(null)' } + if ($limit -is [TimeSpan] -and $limit.Ticks -le 0) { return 'PT0S' } + return $limit.ToString() +} + function Test-RdpMonitorDeployTaskQueryReady { return [bool](Get-Command Get-RdpMonitorScheduledTaskExecutionTimeLimitResolved -ErrorAction SilentlyContinue) } @@ -1112,18 +1132,22 @@ function Test-RdpMonitorDeployMainTaskNeedsUnlimitedExecutionTime { [string]$TaskName = 'RDP-Login-Monitor', [string]$ShareRoot = '' ) - if (-not (Test-RdpMonitorDeployTaskQueryReady)) { - if (-not (Initialize-RdpMonitorDeployTaskQuery -ShareRoot $ShareRoot)) { return $true } - } - return (Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -TaskName $TaskName) + if (-not (Initialize-RdpMonitorDeployTaskQuery -ShareRoot $ShareRoot)) { return $true } + $resolved = Get-RdpMonitorScheduledTaskExecutionTimeLimitResolved -TaskName $TaskName + if ($resolved.Source -eq 'missing') { return $true } + return (-not (Test-RdpMonitorDeployTaskExecutionLimitUnlimitedValue -Limit $resolved.Limit)) } function Get-RdpMonitorDeployMainTaskExecutionTimeLimitLabel { - param([string]$TaskName = 'RDP-Login-Monitor') - if (-not (Get-Command Get-RdpMonitorScheduledTaskExecutionTimeLimitLabel -ErrorAction SilentlyContinue)) { + param( + [string]$TaskName = 'RDP-Login-Monitor', + [string]$ShareRoot = '' + ) + if (-not (Initialize-RdpMonitorDeployTaskQuery -ShareRoot $ShareRoot)) { return '(TaskQuery not loaded)' } - return (Get-RdpMonitorScheduledTaskExecutionTimeLimitLabel -TaskName $TaskName) + $resolved = Get-RdpMonitorScheduledTaskExecutionTimeLimitResolved -TaskName $TaskName + return (Get-RdpMonitorDeployTaskExecutionTimeLimitLabelFromResolved -Resolved $resolved) } function Write-RdpMonitorDeployScheduledTaskVerification { @@ -1142,8 +1166,8 @@ function Write-RdpMonitorDeployScheduledTaskVerification { Write-DeployLog "Задача ${TaskName}: ExecutionTimeLimit проверен через schtasks /XML (Get-ScheduledTask недоступен)." } - if (Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -TaskName $TaskName) { - $label = Get-RdpMonitorScheduledTaskExecutionTimeLimitLabel -TaskName $TaskName + if (-not (Test-RdpMonitorDeployTaskExecutionLimitUnlimitedValue -Limit $resolved.Limit)) { + $label = Get-RdpMonitorDeployTaskExecutionTimeLimitLabelFromResolved -Resolved $resolved Write-DeployLog "ПРЕДУПРЕЖДЕНИЕ: $TaskName ExecutionTimeLimit=$label — ожидался PT0S (без лимита). Проверьте InstallTasks и права администратора." return $false } @@ -1268,7 +1292,7 @@ try { } elseif ($needsWinRmInboundBlock) { Write-DeployLog "Версия совпадает ($shareVerRaw), но в settings отсутствует обязательный блок WinRM inbound — продолжаем деплой." } elseif ($needsTaskExecutionLimitFix) { - $limitLabel = Get-RdpMonitorDeployMainTaskExecutionTimeLimitLabel + $limitLabel = Get-RdpMonitorDeployMainTaskExecutionTimeLimitLabel -ShareRoot $shareRoot Write-DeployLog "Версия совпадает ($shareVerRaw), но RDP-Login-Monitor имеет ExecutionTimeLimit=$limitLabel — перерегистрируем задачи (InstallTasks)." } } diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index de2c899..aa5bbb6 100644 --- a/Login_Monitor.ps1 +++ b/Login_Monitor.ps1 @@ -90,7 +90,7 @@ $script:SkipLogDetailLimit = 15 # строки ниже, если правки «мелкие» и вы не хотите менять отображаемую версию в логах). # Рекомендация: при значимых релизах меняйте и $ScriptVersion, и version.txt одинаково; при только # исправлениях на шаре — достаточно поднять patch в version.txt (например 1.3.0.1). -$ScriptVersion = "2.0.30-SAC" +$ScriptVersion = "2.0.31-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" diff --git a/version.txt b/version.txt index c4da7f5..0744909 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.30-SAC +2.0.31-SAC