Help with BATCH file

Hi. I am trying to create a batch file to solve a problem. The problem is that I've got a finicky VPN client at a remote computer which often thinks it is connected even though it is not allowing data to move through the pipe. The only way to restore connectivity is to exit the client and re-open.

So I want the batch file to ping the server, if there's a response then exit. If it times out, check to see if the VPN client process is running and kill it if so, then wait a few seconds for it to terminate. Then open the VPN client (which will auto-connect upon opening). I will schedule this task to run every 30 minutes or so to insure a somewhat persistent connection.

And finally, I'd like the whole thing to run in the background, so I don't get the big black command screen window popping up every time it runs.

Thanks for your ideas!
[896 byte] By [gurs] at [2007-11-20 4:25:21]
# 1 Re: Help with BATCH file
You can ping with a batch file, but the rest of the things that you desire done, cannot be done with a batch file.

Your problem should not be solved by a batch application but by actually fixing the VPN client.
PeejAvery at 2007-11-9 12:18:39 >
# 2 Re: Help with BATCH file
You can ping with a batch file, but the rest of the things that you desire done, cannot be done with a batch file.

Thanks for the reply. Which of the tasks I wish to accomplish do you feel can't be done from a batch file? I am certainly not an expert, but I thought that batch files were able to (1) run if-then statements, (2) execute ping commands, (3) kill tasks by using the taskkill command and (4) open programs by simply listing the path & filename to the exe file. Which one of those 4 can't be done with a batch file? Perhaps I can find a workaround if I know where the issue is.

I agree with you that diagnosing the VPN is the best option, but I'm just going to have to settle for 2nd best until I've got more time to troubleshoot the VPN!
gurs at 2007-11-9 12:19:49 >
# 3 Re: Help with BATCH file
...(1) run if-then statements, (2) execute ping commands, (3) kill tasks by using the taskkill command and (4) open programs by simply listing the path & filename to the exe file. Which one of those 4 can't be done with a batch file? Perhaps I can find a workaround if I know where the issue is.
A batch file can do all of these. The way it was worded, I did not realize that you wanted applications run, but thought that you actually wanted the batch file to do the VPN work.

One thing though...there is no command to wait a few seconds. Pause is user input activated.
PeejAvery at 2007-11-9 12:20:47 >
# 4 Re: Help with BATCH file
A batch file can do all of these.

Great! Can you give me any guidance on the content of the batch file? I'm not sure how to code it. Thanks.
gurs at 2007-11-9 12:21:46 >
# 5 Re: Help with BATCH file
You still cannot program this from a batch file.

Yes, the ping command can be run, but you cannot get the results except by outputting it into a file. Once the file is outputted you will not be able to parse if there was a connection or not.
PeejAvery at 2007-11-9 12:22:45 >
# 6 Re: Help with BATCH file
While some of those (if not all) were possible in the old DOS days, I doubt there are many who remember how to do it, or if it would run in modern systems.

It'd be much better to write it in another language.
dglienna at 2007-11-9 12:23:44 >
# 7 Re: Help with BATCH file
...I doubt there are many who remember how to do it, or if it would run in modern systems.
Funny that you mention it. I still program in DOS almost once a week. I do most of my network file updating and backups with DOS because it is simple and stable.
PeejAvery at 2007-11-9 12:24:47 >
# 8 Re: Help with BATCH file
Yes, the ping command can be run, but you cannot get the results except by outputting it into a file.

Actually, I think I may have that part of the problem solved (getting the ping results). I have been working on a test batch file, and have come up with a file that will ping a URL and open a file if there is no response to the ping command (and, needless to say, not open the file if there is a response). Here's what I've got so far:

::rem Set IP addresses to ping
SET DEVICE1_IPADDRESS=www.ebay.com
::rem Perform ping, open file if no response
PING -n 1 -l 100 %DEVICE1_IPADDRESS% | find "TTL=" || c:\log.txt

If you copy this to a batch file, you will see that upon receiving no response to the ping (eBay never responds to pings), the referenced file is opened (assuming you have a file named log.txt on your c: drive!). If you change the URL to one that responds to pings, the file is not opened. So I think that addresses your concern that there is no way to capture the output of a ping command.

But what I still haven't figured out how to do is structure the file so that there are nested "if" statements, multiple commands and background / silent operation. What I want to do upon receiving no response is (1) check to see if the vpngui.exe process is running, (2) if it is running, kill it and wait 3 seconds, and (3) open a file. And I'd like it all to run silently, in the background. Can you give me any guidance on those elements?
gurs at 2007-11-9 12:25:51 >