thanks for the effort.. tested it, it didnt work. btw, it doesnt seem complete to me.... T_T
Main Topics
Browse All TopicsCan anyone help me create a batch file or a windows script that will check if the target pc (server for example) is online then if there is a reply it will execute a certain command and if not it will just loop until it gets a ping and finished the execution of the command.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The original intent was to loop until reachable. So both the ping and the file exists approach are suitable. The ping allows for a finer control, however. Based on Steve's code:
I can confirm that. But I have been certain that Steve is right. However, looking into one of my archived batch files, I have used that previously with the || syntax ... Applied to my example, which I still prefer because of the built-in delay (in milliseconds) and suppressing unnecessary output, that is only a small change:
Curious... On Windows 2000 Pro SP4, XP Sp3, Server 2003 SP1? it does NOT set the errorlevel (just tried it again:) Cut out some of the crap but the result is the same. Is this new behaviour on Win 7 or Vista - what are you using?
Steve
C:\Documents and Settings\stephen>ping 10.0.0.1 -n 1 -w 100
Pinging 10.0.0.1 with 32 bytes of data:
Request timed out.
echo %errorlevel%
0
ping 127.0.0.1 -n 1 -w 100
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<10ms TTL=128
echo %errorlevel%
0
C:\Documents and Settings\stephen>ping 10.0.0.1 -n 1 -w 100 || echo OK
Pinging 10.0.0.1 with 32 bytes of data:
Request timed out.
ping 127.0.0.1 -n 1 -w 100 || echo OK
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<10ms TTL=128
Thank you all for your reply on this matter, All posts was very helpful and I tried to combine most of them to reach my goal. eq. leakim971 solution is almost perfect (and "yes" ping does return an errorlevel, so i didn't use the "find" command. I did replaced his >>log.txt to >nul instead since i feel its not that suitable to make a log file for a ping command which loops until it reaches a reply. Again thanks to everyone!
Business Accounts
Answer for Membership
by: leakim971Posted on 2009-10-14 at 20:20:00ID: 25576967
Hello jmiquel18,
Try something like :
Select allOpen in new window