【问题标题】:Detect connection lost with network device and stop application检测与网络设备的连接丢失并停止应用程序
【发布时间】:2018-07-24 11:25:49
【问题描述】:

我想创建一个不断 ping 我的网络设备的批处理应用程序。 一旦 Result 变为 not found 它应该停止某个应用程序或我的 Internet Explorer。

我该如何开始?

我知道我可以用 ping 192.168.0.1 -t 不断地 ping 我的设备,但是如何停止应用程序的结果?

提前致谢,

问候, J

【问题讨论】:

    标签: batch-file cmd internet-explorer-11 ping network-connection


    【解决方案1】:

    I have answered this one previously with a nice little batch file.

    使上述答案起作用所需的修改是:

    :a
    ping -n 1 www.google.com | findstr TTL && goto a
    taskkill /IM <Your Task Name>
    

    这将循环直到连接失败,然后结束脚本。您可以添加另一个goto a 并使其再次循环

    • ping 检查您与所提供位置之间的连接
    • -n 1检查次数(1)
    • | 将结果传递给下一个命令
    • findstr TTL Find String,在输出中找到一个字符串(TTL - Time to live)

    实时ping:Reply from xxx.xxx.xxx.xxx: bytes=32 time=25ms TTL=54

    死机:Reply from xxx.xxx.xxx.xxx: Destination host unreachable.

    • &amp;&amp; 如果上一个命令完成,则继续执行命令。和IF NOT ERRORLEVEL 1一样
    • goto a 简单跳转到脚本中的标签 (:a)

    【讨论】:

    • 'findstr TTL && got a' 是什么意思。谢谢顺便说一句
    • 编辑了答案,为您提供详尽的解释。
    • 当我启动应用程序时这是完美的,但我如何在应用程序使用过程中进行检查?如何实际制作一个while循环?
    • 如果您使用相同的 powershell 启动应用程序,则不能。您将需要第二批并调用它。
    • 同一批,不是powershell,抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    相关资源
    最近更新 更多