求批处理 放开机启动项目里面 如果ping通 某一ip 5次以上 便启动一个程序,不通一直ping。

例如 开机ping 192.168.1.255 ping通5次 执行C:\Program Files\1.exe 不通就一直ping 直到通为止。 不显示窗口。

第1个回答  2013-10-18
@Echo Off
if not "%1"=="h" mshta vbscript:createobject("wscript.shell").run("""%~f0"" h",vbhide)(window.close)&&exit
For /l %%i in (1,1,5) do (Ping -n 1 192.168.1.255 2>nul 1>nul&&Set /a n+=1)
If "%n%"=="5" (Start "" "C:\Program Files\1.exe"&Exit) else (Goto a)
:a
Ping -n 2 192.168.1.255 && (Start "" "C:\Program Files\1.exe") || Goto a

追问

如果没找打1.exe 不就死循环了啊。

追答Ping -n 2 192.168.131.66 &&Goto b || Goto a 
:b
Start "" "C:\Program Files\1.exe"

这样就不会了.

第2个回答  2013-10-18
ping 192.168.1.255
if %ERRORLEVEL% == 0 (call C:\Program Files\1.exe ) else (ping 192.168.1.255)
嚎这里如果CALL调用不了,就改成start本回答被提问者采纳
相似回答