diff --git a/Deploy-LoginMonitor.ps1 b/Deploy-LoginMonitor.ps1 index 526bbbb..be83f3e 100644 --- a/Deploy-LoginMonitor.ps1 +++ b/Deploy-LoginMonitor.ps1 @@ -973,11 +973,14 @@ function Stop-RdpLoginMonitorMainProcesses { } } +function Test-RdpMonitorDeployTaskQueryReady { + return [bool](Get-Command Get-RdpMonitorScheduledTaskExecutionTimeLimitResolved -ErrorAction SilentlyContinue) +} + function Import-RdpMonitorDeployTaskQueryModule { param([string]$ShareRoot = '') $candidates = [System.Collections.Generic.List[string]]::new() - $candidates.Add((Join-Path $InstallRoot 'RdpMonitor-TaskQuery.ps1')) | Out-Null if (-not [string]::IsNullOrWhiteSpace($ShareRoot)) { $candidates.Add((Join-Path $ShareRoot 'RdpMonitor-TaskQuery.ps1')) | Out-Null } @@ -985,17 +988,21 @@ function Import-RdpMonitorDeployTaskQueryModule { if ([string]::IsNullOrWhiteSpace($deployScriptPath)) { $deployScriptPath = $MyInvocation.MyCommand.Path } if (-not [string]::IsNullOrWhiteSpace($deployScriptPath)) { $candidates.Add((Join-Path (Split-Path -Parent $deployScriptPath) 'RdpMonitor-TaskQuery.ps1')) | Out-Null - } else { - try { - $candidates.Add((Join-Path (Resolve-SourceShareRoot) 'RdpMonitor-TaskQuery.ps1')) | Out-Null - } catch { } } + $candidates.Add((Join-Path $InstallRoot 'RdpMonitor-TaskQuery.ps1')) | Out-Null foreach ($candidate in @($candidates)) { - if (Test-Path -LiteralPath $candidate) { + if (-not (Test-Path -LiteralPath $candidate)) { continue } + try { . $candidate + } catch { + Write-DeployLog "Предупреждение: не удалось загрузить $candidate — $($_.Exception.Message)" + continue + } + if (Test-RdpMonitorDeployTaskQueryReady) { return $true } + Write-DeployLog "Предупреждение: $candidate загружен, но функции TaskQuery недоступны — пробуем следующий источник." } return $false } @@ -1003,16 +1010,16 @@ function Import-RdpMonitorDeployTaskQueryModule { function Initialize-RdpMonitorDeployTaskQuery { param([string]$ShareRoot = '') - if (Get-Command Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -ErrorAction SilentlyContinue) { + if (Test-RdpMonitorDeployTaskQueryReady) { return $true } if (Import-RdpMonitorDeployTaskQueryModule -ShareRoot $ShareRoot) { return $true } - Write-DeployLog "RdpMonitor-TaskQuery.ps1 не найден — deploy использует встроенную проверку schtasks /XML." + Write-DeployLog "RdpMonitor-TaskQuery.ps1 недоступен — deploy использует встроенную проверку schtasks /XML." . $script:RdpMonitorDeployTaskQueryInlineScript - return $true + return (Test-RdpMonitorDeployTaskQueryReady) } $script:RdpMonitorDeployTaskQueryInlineScript = { @@ -1101,9 +1108,12 @@ $script:RdpMonitorDeployTaskQueryInlineScript = { } function Test-RdpMonitorDeployMainTaskNeedsUnlimitedExecutionTime { - param([string]$TaskName = 'RDP-Login-Monitor') - if (-not (Get-Command Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -ErrorAction SilentlyContinue)) { - return $true + param( + [string]$TaskName = 'RDP-Login-Monitor', + [string]$ShareRoot = '' + ) + if (-not (Test-RdpMonitorDeployTaskQueryReady)) { + if (-not (Initialize-RdpMonitorDeployTaskQuery -ShareRoot $ShareRoot)) { return $true } } return (Test-RdpMonitorScheduledTaskNeedsUnlimitedExecutionTimeLimit -TaskName $TaskName) } @@ -1117,7 +1127,15 @@ function Get-RdpMonitorDeployMainTaskExecutionTimeLimitLabel { } function Write-RdpMonitorDeployScheduledTaskVerification { - param([string]$TaskName = 'RDP-Login-Monitor') + param( + [string]$TaskName = 'RDP-Login-Monitor', + [string]$ShareRoot = '' + ) + + if (-not (Initialize-RdpMonitorDeployTaskQuery -ShareRoot $ShareRoot)) { + Write-DeployLog "ПРЕДУПРЕЖДЕНИЕ: проверка ExecutionTimeLimit недоступна (TaskQuery не инициализирован)." + return $false + } $resolved = Get-RdpMonitorScheduledTaskExecutionTimeLimitResolved -TaskName $TaskName if ($resolved.Source -eq 'schtasks-xml') { @@ -1211,7 +1229,7 @@ try { $needsExchangeNoisePatch = Test-RdpMonitorSettingsNeedsExchangeNoisePatch -SettingsPath $settingsLocal $needsWinRmInboundBlock = Test-RdpMonitorSettingsNeedsWinRmInboundBlock -SettingsPath $settingsLocal $needsBundleSync = Test-RdpMonitorDeployBundleNeedsSync -ShareRoot $shareRoot - $needsTaskExecutionLimitFix = Test-RdpMonitorDeployMainTaskNeedsUnlimitedExecutionTime + $needsTaskExecutionLimitFix = Test-RdpMonitorDeployMainTaskNeedsUnlimitedExecutionTime -ShareRoot $shareRoot $needsSacBootstrap = $needsSettingsBootstrap -or $needsBundleSync -or $needsDisplayNameHint -or $needsDailyReportHint -or $needsDailyReportRepair -or $needsExchangeNoisePatch -or $needsWinRmInboundBlock -or $needsTaskExecutionLimitFix if (Test-RdpMonitorExchangeServerRole) { @@ -1321,8 +1339,7 @@ try { Write-DeployLog "InstallTasks выполнен (код 0)." } - [void](Initialize-RdpMonitorDeployTaskQuery -ShareRoot $shareRoot) - [void](Write-RdpMonitorDeployScheduledTaskVerification) + [void](Write-RdpMonitorDeployScheduledTaskVerification -ShareRoot $shareRoot) [System.IO.File]::WriteAllText($VersionStampPath, "$shareVerRaw`r`n", $Utf8Bom) Write-DeployLog "Записана метка версии: $VersionStampPath" diff --git a/Login_Monitor.ps1 b/Login_Monitor.ps1 index a71a54e..de2c899 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.29-SAC" +$ScriptVersion = "2.0.30-SAC" # Логи (все под InstallRoot) $LogFile = Join-Path $script:InstallRoot "Logs\login_monitor.log" diff --git a/version.txt b/version.txt index 11d0641..c4da7f5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.29-SAC +2.0.30-SAC