我尝试通过CMD重启计算机。 我只能找到并检查没有运行>>重启计算机的程序。 但我找不到检查网络>>重启计算机的解决方案。
我的代码是:
:start
tasklist | find "%proc%" >nul && (
echo %proc% is OK
timeout /t %time%
goto :start ) || (
echo ERROR! RESTART WINDOWS!...
timeout /t 30
shutdown.exe /r /t 00
)
请帮忙。
您可以ping远程地址(在本例中为google.com)并使用errorLevel确定您是否已连接。以下代码将每秒检查一次连接,如果检测不到连接,则立即重启。
:start
ping -n 1 google.com >nul
if errorlevel 1 goto noConnection
timeout /t 1 /nobreak >nul
goto :start
:noConnection
echo ERROR: No connection found, restarting!
shutdown /r