batch checks internet connection

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jin
Posts: 1
Joined: 16 Mar 2011 10:32

batch checks internet connection

#1 Post by Jin » 16 Mar 2011 10:42

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.

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: batch checks internet connection

#2 Post by shiva » 15 Sep 2011 01:43

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

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: batch checks internet connection

#3 Post by nitt » 15 Sep 2011 16:01

@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


:/

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: batch checks internet connection

#4 Post by shiva » 16 Sep 2011 00:52

Hi,
i just write the code to get u understand,
i doesnt thing of making small


:)
:lol:
:)

Post Reply