Page 1 of 1

batch checks internet connection

Posted: 16 Mar 2011 10:42
by Jin
hi,

i wrote a batch that runs on windows user logon and pings a website. if ping is succesful, it starts various tools (like mail icq etc). otherwise if i'm offline i don't need those tools running on my notebook.
but now i want to enhance this batch. i know there is a tool called srvany.exe which makes it possible to run a bat(oder exe) file as a service. yet i dont know whats the best way to write a batch which constantly checks if internet-connection is available. or should i keep pinging that website forever? maybe one of you know of another option for me to solve this issue, because i'm still new to batch scripting.

thanks in advance.

Re: batch checks internet connection

Posted: 15 Sep 2011 01:43
by shiva
Hi,
to the specifications i have made the batch script for you,

you need to change in one line while you execute the code,
it is the path of your srvany.exe ,
echo statements are for your undersanding purpose,
the code was

connect.bat


@echo off

set server=www.google.com

:check

ping %server% > NUL
if %ERRORLEVEL%==0 (
@echo internet was conncted
goto working
) else (
@echo internet was notconnected
goto check
)
:working
echo write code to call srvany.exe
:update
ping %server% > NUL
if %ERRORLEVEL%==0 (
@echo internet was connected
goto update
) else (
@echo internet was notconnected
goto check
)
@echo on


//this executes continuously, updates connection for every time and calls srvany.exe only once after getting internet connection

Re: batch checks internet connection

Posted: 15 Sep 2011 16:01
by nitt
@shiva

Kinda long...

Code: Select all

@echo off
ping google.com > nul && (echo You are connected to the internet!) || (echo You are not connected to the internet!)
pause


:/

Re: batch checks internet connection

Posted: 16 Sep 2011 00:52
by shiva
Hi,
i just write the code to get u understand,
i doesnt thing of making small


:)
:lol:
:)