windows批处理:如何随时检查网络是否已断开?
我想知道是否有可能(以及如何)随时检测网络连接是否崩溃。我已经创建了一个带有检查功能的小脚本,但是它每隔几秒钟通过ping检查一次网络,并且工作不正常。我被告知没有检测到微切口 这是来源:windows批处理:如何随时检查网络是否已断开?,windows,batch-file,networking,Windows,Batch File,Networking,我想知道是否有可能(以及如何)随时检测网络连接是否崩溃。我已经创建了一个带有检查功能的小脚本,但是它每隔几秒钟通过ping检查一次网络,并且工作不正常。我被告知没有检测到微切口 这是来源: @echo off :: Interval of time the network is checked: 30 seconds set delay_time=30 :: Delay between the kill and the start of the process set delay_time_k
@echo off
:: Interval of time the network is checked: 30 seconds
set delay_time=30
:: Delay between the kill and the start of the process
set delay_time_kill_start=5
:: Example process to kill and start
set process_to_kill=calc.exe
set process_to_start=calc.exe
:: local network to ping to check the connection
set ping_url=10.51.111.223 -n 1 -w 1000
:test-connection
Ping %ping_url%
if errorlevel 1 (
echo No hay conexión
:is-connected
Ping %ping_url%
if errorlevel 1 (
@echo on
echo trying to connect
@echo off
timeout 10
goto :is-connected
) else (
@echo on
echo kill the process
@echo off
taskkill /IM %process_to_kill% /f
timeout %delay_time_kill_start%
@echo on
echo start the process
@echo off
%process_to_start%
goto test-connection
)
) else (
timeout %delay_time%
goto test-connection
)
pause
基本上,我想要的是在任何时候网络连接丢失时杀死一个进程并重新启动它,因为当连接崩溃时,该进程会冻结
例如,我想每30分钟检查一次网络连接是否在过去半小时内的任何时候丢失,如果是,则终止并启动该过程
如果不每隔几秒钟执行ping策略,是否可能?您不能在if语句中添加标签。好吧,这些“微切”是在硬件(或驱动程序)级别处理的(我认为最多几秒钟)。它们甚至不与windows通信,因此您检测到它们的机会是。。。非常接近于零。所以没有办法重新启动一个冻结的进程?我要求检查网络,因为这是它发生的时候,但如果有另一种方法来检测进程是否冻结以重新启动它,那就太好了。