Ping Bat File

January 11, 2011 at 09:35:29
Specs: Windows 7
I want to create a bat file to ping an ip address for window 7, when it get error message such as "Request time out", it will execute a file. After the execution, it will continue ping the ip address again. Looping forever.

See More: Ping Bat File

Report •


#1
January 11, 2011 at 14:24:26
I never recommend doing this in an endless loop because it will put undo network trafic on your network and eatup bandwidth. IT will also eat CPU cycles. Never a good idea to put something in an endless loop BUT if you want to here is your code.

@echo off
:Start
ping 192.168.1.1 -n 1 > NUL
if ERRORLEVEL 1 set call c:\programtorun.exe
goto Start


Report •

#2
January 12, 2011 at 00:05:46
"if ERRORLEVEL 1 set call c:\programtorun.exe"

set call?

Happy is ONE who says I am an OttoMAN.


Report •

#3
January 12, 2011 at 03:09:05
Thanks for the code ace_omega, but there is error after i do some changes. Thanks for your consent but i still need it.

@echo off
:Start
ping 192.168.1.1 -n 1 > NUL
if ERRORLEVEL 1 set call "C:\Users\Nicholas\Desktop\File.txt"
goto Start

Error that i get is= "Environment variable call "C:\Users\Nicholas\Desktop\File.txt" not defined"

Please help me out with this, thanks in advance.


Report •

Related Solutions

#4
January 12, 2011 at 04:32:04
That's what I ment lol, set call isnt't correct here.

Try 'call' or 'start' without 'set'

@echo off
:Start
ping 192.168.1.1 -n 1 > NUL
if ERRORLEVEL 1 start "C:\Users\Nicholas\Desktop\File.txt"
goto Start

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#5
January 12, 2011 at 07:30:59
Thanks for the reply MUs but there is a problem. When i use to call File.bat. It doesn't work but if use Start File.bat. Multiple of CMD prompt up non-stop.

Report •

#6
January 12, 2011 at 07:53:27
It's alright bro. I already solved the problem. Use Start then need to add /wait. This will solve the unlimited pop up problem

Report •

#7
January 19, 2011 at 09:17:02
Oops yep it should have been..

    
@echo off
    :Start
    ping 192.168.1.1 -n 1 > NUL
    if ERRORLEVEL 1 call c:\programtorun.exe
    goto Start

if you want to display a text file then the code would be...

    
@echo off
    :Start
    ping 192.168.1.1 -n 1 > NUL
    if ERRORLEVEL 1 (
       type "C:\Users\Nicholas\Desktop\File.txt"
       pause
    )
    goto Start

Viewing a text file and running a program are different things.

AGAIN
I never recommend doing this in an endless loop because it will put undo network trafic on your network and eatup bandwidth. IT will also eat CPU cycles. Never a good idea to put something in an endless loop. You really should take out the goto loop and run this under a MS Scheduler event.

Now I have no idea what is in your File.bat. Can you post the code.


Report •

#8
January 20, 2011 at 03:13:04
@ECHO OFF
:Start
PING 192.168.1.1 -n 5 > NUL
IF ERRORLEVEL 1 START /WAIT File.bat
GOTO Start

There is not full tutorial on how to use Window 7 MS Scheduler event.


Report •


Ask Question