Автоматически перезагружать Windows8, если нет интернет-активности

5460
mrpatg

У меня есть медиасервер, расположенный в очень неудобной части моего дома. Иногда мне приходится сбрасывать настройки маршрутизатора, иначе он сам себя сбросит. Проблема в том, что ПК по какой-то причине теряет связь, и я вынужден выйти на улицу, вокруг дома, в подвал, над кучей игрушек, гирь и коробок, чтобы нажать кнопку, чтобы перезагрузить его.

Я хотел бы, чтобы он проверял сам себя каждые 5-10 минут и автоматически перезагружался, если он не может пропинговать данный адрес / IP.

Есть идеи как это сделать?

1

2 ответа на вопрос

2
Fazer87

Batch File:

ping 192.168.1.1 IF ERRORLEVEL 1 SHUTDOWN -R -T 00 

Powershell:

if (!(Test-Connection 192.168.1.1 -quiet)) 

VBScript:

 If Reachable("192.168.1.1") Then WScript.Run("shutdown -r -t 00") End If Function Reachable(strComputer) Dim wmiQuery, objWMIService, objPing, objStatus wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'" Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set objPing = objWMIService.ExecQuery(wmiQuery) For Each objStatus in objPing If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then Reachable = False 'if computer is unreacable, return false Else Reachable = True 'if computer is reachable, return true End If Next End Function 

Any of these can be scheduled to work as a task at an intervall to suit you - an if scheduled to run with "highest priviledges", then will be able to overcome any potential UAC problems.

Bear in mind this only checks connectivity to your router. It maybe worth replacing the IP with one such as www.google.com or similar.. make it something which you know replies (do a manual ping) and make sure it isnt a dodgy site which is vulnerable to downtime.. you dont want your pc rebooting for nothing

0
Keltari

Here is a PowerShell script that will do it. Just run it as a scheduled task as frequently as you want. It uses Restart-Computer, you may need to use -force, depending on circumstances. Check the link for options.

If (!(Test-Connection 192.168.20.199 -quiet)) { #Write-Host "Not connected" Restart-Computer } Else { #Write-Host "Connected" } 

I included a full If/Else statement, however you can do this in one line. The full If/Else gives you the flexibility to do more if needed. Here is a 1 liner:

if (!(Test-Connection 192.168.20.199 -quiet)) 

If you cannot ping your router when it fails, use your router's address in the script. That would be the best option. You could test a website like yahoo.com. The problem with testing an external site is that:

  1. The remote address has to accept pings
  2. The remote address might be down, which would make the machine reboot

Похожие вопросы