Загрузка данных
# ============================================
# EmergencyAlert.ps1
# Окно в стиле "БЕСПИЛОТНАЯ ОПАСНОСТЬ"
# Управляется файлом-триггером alert.txt
# ============================================
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
# ------------------- НАСТРОЙКИ -------------------
$alertFile = "\\server\AlertShare\alert.txt"
$alertDoneFile = "\\server\AlertShare\alert_done_$env:COMPUTERNAME.txt"
$checkInterval = 5
$AlertTitle = "ЭКСТРЕННОЕ ОПОВЕЩЕНИЕ"
$AlertMessage = @"
Срочно покиньте помещение
"@
$SoundRepeat = $true
# -------------------------------------------------
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
while ($true) {
if (Test-Path $alertFile) {
# Проверяем, не показывали ли уже окно на этом ПК
if (-not (Test-Path $alertDoneFile)) {
$Global:AlertClosed = $false
# ---------- СОЗДАЁМ ФОРМУ ----------
$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()
})
# Запрещаем закрытие
$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)
# ---------- КНОПКА (фиксирует получение, но НЕ закрывает окно) ----------
$ButtonOk = New-Object System.Windows.Forms.Button
$ButtonOk.Text = "ПОДТВЕРЖДАЮ"
$ButtonOk.Font = New-Object System.Drawing.Font("Arial", 18, [System.Drawing.FontStyle]::Bold)
$ButtonOk.Size = New-Object System.Drawing.Size(300, 80)
$ButtonOk.BackColor = [System.Drawing.Color]::White
$ButtonOk.ForeColor = [System.Drawing.Color]::DarkRed
$ButtonOk.FlatStyle = "Popup"
$Form.Add_Shown({
$ButtonOk.Left = ($Form.ClientSize.Width - $ButtonOk.Width) / 2
$ButtonOk.Top = ($Form.ClientSize.Height * 0.78) - ($ButtonOk.Height / 2)
})
$ButtonOk.Add_Click({
# Создаём файл-метку, что на этом ПК подтвердили
try {
"ПК: $env:COMPUTERNAME`nПользователь: $env:USERNAME`nВремя: $(Get-Date -Format 'dd.MM.yyyy HH:mm:ss')" | Out-File $alertDoneFile -Force -Encoding UTF8
} catch {}
# Меняем текст кнопки, но окно НЕ закрываем
$ButtonOk.Text = "ПРИНЯТО. ЖДИТЕ."
$ButtonOk.Enabled = $false
})
$Form.Controls.Add($ButtonOk)
# ---------- ФУТЕР ----------
$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() })
$Form.ShowDialog()
# Сюда попадаем только когда окно закрыто (по отбою тревоги)
$FocusTimer.Stop()
if ($SoundRepeat) { $SoundTimer.Stop() }
$Form.Dispose()
# Удаляем метку, чтобы при повторной тревоге окно снова показалось
if (Test-Path $alertDoneFile) {
try { Remove-Item $alertDoneFile -Force -ErrorAction SilentlyContinue } catch {}
}
}
}
else {
# Тревоги нет — удаляем метку
if (Test-Path $alertDoneFile) {
try { Remove-Item $alertDoneFile -Force -ErrorAction SilentlyContinue } catch {}
}
}
Start-Sleep -Seconds $checkInterval
}