вставьте в powershell от имени админа:
#requires -RunAsAdministrator
$ErrorActionPreference = 'Stop'
$taskName = 'WutheringWaves-Restore-DNS'
$marker = '# TEMP-WUTHERINGWAVES-DNS'
$hostsPath = Join-Path $env:SystemRoot 'System32\drivers\etc\hosts'
$ascii = [System.Text.Encoding]::ASCII
# Читаем файл полностью, затем закрываем его перед записью
$lines = [System.IO.File]::ReadAllLines($hostsPath)
[string[]]$filtered = @(
$lines | Where-Object { $_ -notlike "*$marker*" }
)
[System.IO.File]::WriteAllLines($hostsPath, $filtered, $ascii)
# Добавляем временные записи
[string[]]$entries = @(
"185.135.82.119 wutheringwaves.ru $marker",
"185.135.82.119 api.wutheringwaves.ru $marker"
)
[System.IO.File]::AppendAllLines($hostsPath, $entries, $ascii)
# Создаём скрипт очистки через 7 дней
$cleanupPath = Join-Path $env:ProgramData 'WutheringWaves-Restore-DNS.ps1'
$cleanupScript = @'
$taskName = 'WutheringWaves-Restore-DNS'
$marker = '# TEMP-WUTHERINGWAVES-DNS'
$hostsPath = Join-Path $env:SystemRoot 'System32\drivers\etc\hosts'
$lines = [System.IO.File]::ReadAllLines($hostsPath)
[string[]]$filtered = @(
$lines | Where-Object { $_ -notlike "*$marker*" }
)
[System.IO.File]::WriteAllLines(
$hostsPath,
$filtered,
[System.Text.Encoding]::ASCII
)
ipconfig /flushdns | Out-Null
Unregister-ScheduledTask `
-TaskName $taskName `
-Confirm:$false `
-ErrorAction SilentlyContinue
'@
[System.IO.File]::WriteAllText($cleanupPath, $cleanupScript, $ascii)
# Создаём задачу автоматической очистки
$action = New-ScheduledTaskAction `
-Execute 'powershell.exe' `
-Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$cleanupPath`""
$trigger = New-ScheduledTaskTrigger `
-Once `
-At (Get-Date).AddDays(7)
$principal = New-ScheduledTaskPrincipal `
-UserId 'SYSTEM' `
-LogonType ServiceAccount `
-RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable
Register-ScheduledTask `
-TaskName $taskName `
-Action $action `
-Trigger $trigger `
-Principal $principal `
-Settings $settings `
-Force | Out-Null
ipconfig /flushdns | Out-Null
Write-Host 'Готово: записи добавлены и будут удалены через 7 дней.'