Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make (hopefully a simple) script that when run pings my mobile device. If the mobile is connected to the network it will execute one command and if not it will execute another.

I've tried with the following command:

ping -n 1 (The IP) >nul    

start home.mp3    
GOTO end

start alarm.mp3    
GOTO end


This actually worked once, but since then it doesn't work after the first ping. Is it something I'm missing? Perhaps there's an easier way of doing this?

share|improve this question
FYI - the reason this doesn't work is because the ping command does not set the errorlevel based on the result of the ping. We used to have a command line tool called "alive" that did that. – uSlackr Jun 8 '12 at 2:30
ping -n 1 xxx.yyy.zzz.www | findstr TTL && start home.mp3
ping -n 1 xxx.yyy.zzz.www | findstr TTL || start alarm.mp3
share|improve this answer
This worked perfectly. Finally I can go to sleep. Thank you so much!!! – Anton Johnsson Jun 7 '12 at 23:47
@AntonJohnsson So this answered your question? Why did you not accept the answer? – 030 Oct 18 '14 at 15:43
ping -n 1 COMPUTERNAME | findstr TTL && start home.mp3 || start alarm.mp3
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.