ping bat file problem

May 23, 2010 at 08:37:15
Specs: Windows XP
im trying to write a bat file that will keep pinging a ip address lets say 192.168.0.104. if the ping times out ("Request timed out")then it will restart my computer

can anyone help me with the codes.. thank you


See More: ping bat file problem

Report •

#1
May 23, 2010 at 09:20:19
ping 192.168.0.104 > nul || shutdown -s -f

Report •

#2
May 23, 2010 at 09:50:00
For an infinite loop of IVO's command

for /l %%a in (1 0 1) do ping 192.168.0.104 > nul || shutdown -s -f


Report •

#3
May 23, 2010 at 11:02:14
thx guyz. does that mean i can schedule a task so it starts with windows and restarts the computer when ever the ping times out??

Report •

Related Solutions

#4
May 23, 2010 at 11:47:47
I believe you have to rely on "find" to generate the error indication. I don't think "ping" throws an error when the recipient fails to respond.
ping -n 1 192.168.0.188 | find "Reply" || echo shutting down

Report •

#5
May 23, 2010 at 12:54:49
To launch the command when Windows starts just store Judago's script into the Startup Folder, there is no need to schedule the script.

@nbrane, Yes try to believe, the ping command returns an error code when it gets no response.


Report •

#6
May 23, 2010 at 14:24:03
I am puzzled as to why you would want to restart your system just because a ping times out.

(By the way, to restart you need "shutdown -r")


Report •

#7
May 23, 2010 at 20:06:02
@IVO: you're right - i was using an older version of ping that does not set the errorlevel. the current version does.

Report •

#8
May 24, 2010 at 02:06:53
Waiting for an answer to klint's question here the ultimate version of the requested script to run minimized on the task bar so not annoying.

@echo off & setlocal
if not defined %~n0 (
  set %~n0=RUN
  start "" /Min "%~0"
  exit
)
for /L %%j in (0 0 1) do ping 192.168.0.104 > nul || shutdown -r -f
:: End_Of_Batch


Report •

#9
May 24, 2010 at 02:17:37
In w2k, which is more like XP than anything I know of, ping only returns non-zero if it fails to resolve. Otherwise 0, reply or no reply.


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question