Загрузка данных
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
# ------------------- НАСТРОЙКИ -------------------
$alertFile = "\\server\AlertShare\alert.txt"
$checkInterval = 5
$AlertTitle = "ЭКСТРЕННОЕ ОПОВЕЩЕНИЕ"
$AlertMessage = @"
Срочно покиньте помещение
"@
$SoundRepeat = $true
# -------------------------------------------------
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
while ($true) {
# Ждём появления файла тревоги
while (-not (Test-Path $alertFile)) {
Start-Sleep -Seconds $checkInterval
}
# ---------- СОЗДАЁМ ФОРМУ ----------
$Form = New-Object System.Windows.Forms.Form
$Form.Text = $AlertTitle
$Form.StartPosition = "CenterScreen"
$Form.FormBorderStyle = "FixedDialog"
$Form.ControlBox = $false
$Form.TopMost = $true
$Form.WindowState = "Maximized"
$Form.BackColor = [System.Drawing.Color]::FromArgb(192, 0, 0)
$Form.KeyPreview = $true
# Таймер возврата фокуса
$FocusTimer = New-Object System.Windows.Forms.Timer
$FocusTimer.Interval = 200
$FocusTimer.Add_Tick({
$Form.Activate()
$Form.BringToFront()
})
# Таймер проверки отбоя
$CheckTimer = New-Object System.Windows.Forms.Timer
$CheckTimer.Interval = 1000
$CheckTimer.Add_Tick({
if (-not (Test-Path $alertFile)) {
$Form.Close()
}
})
# Запрещаем закрытие пользователем
$Form.Add_FormClosing({
if ($_.CloseReason -eq "UserClosing") {
$_.Cancel = $true
}
})
# ---------- ЗАГОЛОВОК ----------
$LabelTitle = New-Object System.Windows.Forms.Label
$LabelTitle.Text = "БЕСПИЛОТНАЯ ОПАСНОСТЬ"
$LabelTitle.Font = New-Object System.Drawing.Font("Arial", 32, [System.Drawing.FontStyle]::Bold)
$LabelTitle.ForeColor = [System.Drawing.Color]::White
$LabelTitle.AutoSize = $true
$LabelTitle.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelTitle.Left = ($Form.ClientSize.Width - $LabelTitle.Width) / 2
$LabelTitle.Top = ($Form.ClientSize.Height * 0.15) - ($LabelTitle.Height / 2)
})
$Form.Controls.Add($LabelTitle)
# ---------- ОСНОВНОЙ ТЕКСТ ----------
$LabelMessage = New-Object System.Windows.Forms.Label
$LabelMessage.Text = $AlertMessage
$LabelMessage.Font = New-Object System.Drawing.Font("Arial", 20)
$LabelMessage.ForeColor = [System.Drawing.Color]::White
$LabelMessage.AutoSize = $true
$LabelMessage.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelMessage.Left = ($Form.ClientSize.Width - $LabelMessage.Width) / 2
$LabelMessage.Top = ($Form.ClientSize.Height / 2) - ($LabelMessage.Height / 2)
})
$Form.Controls.Add($LabelMessage)
# ---------- ФУТЕР ----------
$LabelFooter = New-Object System.Windows.Forms.Label
$LabelFooter.Text = "Ждите дальнейших указаний"
$LabelFooter.Font = New-Object System.Drawing.Font("Arial", 12, [System.Drawing.FontStyle]::Italic)
$LabelFooter.ForeColor = [System.Drawing.Color]::LightGray
$LabelFooter.AutoSize = $true
$LabelFooter.TextAlign = "MiddleCenter"
$Form.Add_Shown({
$LabelFooter.Left = ($Form.ClientSize.Width - $LabelFooter.Width) / 2
$LabelFooter.Top = ($Form.ClientSize.Height * 0.92) - ($LabelFooter.Height / 2)
})
$Form.Controls.Add($LabelFooter)
# ---------- ЗВУК ----------
if ($SoundRepeat) {
$SoundTimer = New-Object System.Windows.Forms.Timer
$SoundTimer.Interval = 10000
$SoundTimer.Add_Tick({ [System.Console]::Beep(800, 500) })
$SoundTimer.Start()
}
# ---------- ПОКАЗЫВАЕМ ФОРМУ ----------
$Form.Add_Shown({
$FocusTimer.Start()
$CheckTimer.Start()
})
$Form.ShowDialog()
# Закрытие по отбою
$FocusTimer.Stop()
$CheckTimer.Stop()
if ($SoundRepeat) { $SoundTimer.Stop() }
$Form.Dispose()
}