Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch check for connection and control programstar  (Read 12310 times)

0 Members and 1 Guest are viewing this topic.

2holdon

  • Guest
batch check for connection and control programstar
« on: April 08, 2006, 08:33:09 AM »
Hi all,

PROBLEM:
I am using the same internet connection with two other persons. In order to not overuse our shared bandwith i would like a script/batch file, etc that checks if any of the two is online. if non of them is online, a download should start automatically (via program target.exe).

if on the other hand one of them goes online(meaning they start their computers) the download manager should stop (i wouldnīt mind just killing the process, if that makes it any easier.).

so this script/or batch file would need to check every ~15 min if one of them is online.

I thought about realizing it with a small batch script and just use a successful ping as a sign of them being online. unfortunately my programming skills - even with batch files - are very limited. so i would really appreciate your help on this.

In case I am trying to invent something, that already exists, please point me to it.

FIRST TRY:
so far i have reached this solution for my problem.

process is a little tool i used to kill a process from commandline. and the last ping is just to put a little delay in the whole thing. the rest should be self explaining.

But: It sometimes hangs, e.g. when i pull out my network cable. i donīt know why, but it would be great if in case of hangup the program would restart itself.
also, as you may have noticed, in case of "dead" the target application will start every time the check is performed succesfully. does anybody know how to tell the batch file not to start a process if it is already running?

And one last thing, would it be possible to run this as a background process, without appearing in the taskbar.

I would really appreciate any support on this. thanks in advance.


Code of Batch file es.bat

Code: [Select]
ECHO OFF

cd %windir%  > nul

:pingfabi
@ping 192.168.2.10 -n 1 > nul
@IF ERRORLEVEL 1 GOTO pingtobi
@IF ERRORLEVEL 0 GOTO alive

:pingtobi
@ping 192.168.2.118 -n 1
@IF ERRORLEVEL 1 GOTO pingnils
@IF ERRORLEVEL 0 GOTO alive

:pingnils
@ping 192.168.2.150 -n 1 > nul
@IF ERRORLEVEL 1 GOTO dead
@IF ERRORLEVEL 0 GOTO alive

:dead
@C:\programme\target\target.exe  > nul
@GOTO end

:alive
@process -q target.exe  > nul
@GOTO end

:end
ECHO *
ping 127 -n 1
es.bat
« Last Edit: April 08, 2006, 12:43:46 PM by 2holdon »

T-Chai

  • Guest
Re: batch check for connection and control program
« Reply #1 on: April 11, 2006, 05:31:45 AM »
I think making a program that allow what you want to do is more effective but with the lac of knowlege it is hard to make it come true.
Try some network monitoring software

2holdon

  • Guest
Re: batch check for connection and control program
« Reply #2 on: April 14, 2006, 10:46:01 AM »
Thanks for your answer.

The Batch file is up and working. But since it is not really a nice solution, I decided to get into programming with c++ to figure out a nicer solution. This is not gonna happen anytime soon, but its always nice to have something to look forward to... ;-)


weasel550

  • Guest
Re: batch check for connection and control program
« Reply #3 on: April 18, 2006, 02:35:57 PM »
Quote
Thanks for your answer.

The Batch file is up and working. But since it is not really a nice solution, I decided to get into programming with c++ to figure out a nicer solution. This is not gonna happen anytime soon, but its always nice to have something to look forward to... ;-)


Yes, you can do this with C++.  Once you learn some basics, google winsock tutorials  ;)