1.

Solve : Networking Batch File?

Answer»

Dear All,

Need to make a batch file by giving a ping command to a particular IP, and if the link is down it should give an pop up to an .exe file, i have already made an .exe file with the VB6.0,

So kindly if any one can help me on this...

Regards,
Saravanantry:
Code: [Select]set connect=<ip>
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start <exe>
) else (
echo Successfully connected to %connect%
)
pause >nul

replace with the ip you wish to check and with a path to your .exe you with top RUN on failure.Hi, Lemonilla,
Great
Thanks for the help....
but in this below program, i want to add a loop so that when link goes down suddenly it should directly pop up the .exe file
so that we will be aware of that
so can u pls help me out in this.



@echo off

set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
) else (
echo Successfully connected to 74.125.236.115
ping www.google.com -t
)
pause >nulHI..

Compare to the above given program i have made a small changes here

@echo off
:loop
set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
)else (
echo Successfully connected to 74.125.236.115
ping www.google.com -w 4
)
Goto loop
pause >nul


But in this program WHENEVER i disconnect my internet connection he keeps poping up the .exe file until the internet connection comes,
so is there any way that only 1 time i have to get the pop up of .exe file
Please help

Regards,
Saravanan
This is untested: The random number just lets you know that the batch is still running.

Code: [Select]@echo off
set connect=74.125.236.115
:loop
echo %random%
ping %connect% -n 2 >nul
if not errorlevel 1 (
echo Successfully connected to %connect%
ping localhost -n 10 >nul
Goto loop
) else (
start "" "F:\Link Files\vb6exe.exe"
)
Hmm,,,

Not working... any other suggestion for the below :

@echo off

set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
) else (
echo Successfully connected to 74.125.236.115
ping www.google.com -t
)
pause >nul


Need to edit in this program itself...


Quote from: sarava_1986 on April 18, 2013, 01:29:02 AM

Hmm,,,

Not working...

I tested my last contribution and it works fine. What do you see on the screen?Quote from: foxidrive on April 18, 2013, 03:46:01 AM
I tested my last contribution and it works fine. What do you see on the screen?
From what I can see, the code the OP posted is not your most recent contribution, but is just the code from lemonilla with the loop removed. Maybe the OP wants to run the EXE file when the connection is down, and then continue to test for a connection, but only run the EXE once.

That is complicated by the fact that the connection could flutter and go up and down rapidly. We'd need to know how he wants to handle that.Hi All,

Below is my Query to make a batch file :

1. My ping to Google.com should continuously be on so that i can see the reply from the site
2. As my link goes down (Request time out) it should give me an pop of an .exe file (which i have made) only once, and it should continuously check the connection when it comes up.

Regards,
Saravanan My ping isn't working in general, try this out, and see if it works (or if it's close to what you want.)
Code: [Select]@echo off
set a=0
:loop
ping www.google.com -n 1 >nul 2>&1
if "%errorlevel%"=="0" set a=0
if "%errorlevel%"=="1" if "%a%"=="0" call :loss
goto loop

:loss
start FILE.exe
set a=1
goto :eof
Hi Lemonilla,

the command which u gave me last one, when ever i used to run it, it just shows blank cmd screen.


Please help me on the below command :
*******************************************************************************
@echo off
:PING
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN
:TRYAGAIN
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO FAILURE!
ECHO Let me try a BIT more, please wait...
@echo off
start /d "c:\Ping files\Link Files" et.exe
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :FAILURE
:SUCCESS
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active Internet connection
ping www.google.com -w 4
goto PING
:FAILURE
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO Kindly Check the connection.........!
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
goto PING
sleep 20
:END
*******************************************************************************

When i run the above batch file
I get:
"Please see the screen shot 1.jpg as attached"

and when i disconnect my network cable
I get:
"Please see the screen shot of 2.jpg as attached"

So in this i just want that it should display only once the error "ET link is down" when the link goes down.
and it should keep checking the link status....

So can you please modify on the above program and resend at the earliest.

Hope you got my needs

Thanks,

Regards,
Saravanan

[recovering disk space, attachment deleted by admin]try:
Code: [Select]@echo off
set a=0

:PING
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN

:TRYAGAIN
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO FAILURE!
ECHO Let me try a bit more, please wait...
@echo off
if "%a%"=="1" start /d "c:\Ping files\Link Files" et.exe
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :FAILURE

:SUCCESS
set a=1
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active Internet connection
ping www.google.com -w 4
goto PING

:FAILURE
set a=0
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO Kindly Check the connection.........!
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
goto PING

%a% holds the value of the last ping (success/failure). When it checks to run your exe, it checks to see if the last ping was a failure, and then does not run.

About the blank screen, I did that purpusfuly, as I figured it would run in the background and would be annoying with lots of flashing text. Here is some with text:
Code: [Select]@echo off
set a=1

:loop
ping www.google.com -n 1 >nul 2>&1
if "%errorlevel%"=="0" (
if "%a%"=="1" cls
if "%a%"=="1" echo Connected
set a=0
)
if "%errorlevel%"=="1" if "%a%"=="0" call :loss
goto loop

:loss
cls
echo Connection Error.
echo Reconnecting. . .
start /d "c:\Ping files\Link Files" et.exe
set a=1
goto :eof
It should write only "Connected" while connected, and write "Connection Error. Reconnecting. . . " while not. You will have to test it to check though. Also changed 'start FILE.exe' to 'start /d "c:\Ping files\Link Files" et.exe' from your code.[/code]alt + printscreen for screen shots!Hi Lemonilla,

Awesome...... it has started working, thanks a lot, it was a excellent help by you...

One last thing in the last program you have edited and send to me... in that when the .exe file runs can that .exe file is it possible to display on the other computer which is in the network.

Regards,
Saravanan. U


Discussion

No Comment Found