feat: graceful restart without Stop-Process; SAC key in settings example

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-05-27 14:43:04 +10:00
parent 8a10e471db
commit 3e0f556f6d
8 changed files with 223 additions and 27 deletions
+29
View File
@@ -0,0 +1,29 @@
<#
.SYNOPSIS
Graceful restart RDP Login Monitor без Stop-Process.
.DESCRIPTION
settings — перечитать login_monitor.settings.ps1 в том же процессе PowerShell.
recycle — корректно завершить монитор и запустить новый процесс (после обновления Login_Monitor.ps1).
.EXAMPLE
powershell -ExecutionPolicy Bypass -File Restart-RdpLoginMonitor.ps1
powershell -ExecutionPolicy Bypass -File Restart-RdpLoginMonitor.ps1 -Recycle
#>
[CmdletBinding()]
param(
[switch]$Recycle
)
$ErrorActionPreference = 'Stop'
$installRoot = [System.IO.Path]::GetFullPath("$env:ProgramData\RDP-login-monitor")
$monitorScript = Join-Path $installRoot 'Login_Monitor.ps1'
if (-not (Test-Path -LiteralPath $monitorScript)) {
Write-Error "Не найден: $monitorScript"
exit 1
}
$args = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $monitorScript, '-RequestRestart')
if ($Recycle) { $args += '-Recycle' }
& "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" @args
exit $LASTEXITCODE