CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2007
    Posts
    4

    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!

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2007
    Posts
    4

    Re: Help with BATCH file

    Quote Originally Posted by PeejAvery
    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!

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Help with BATCH file

    Quote Originally Posted by gurs
    ...(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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2007
    Posts
    4

    Re: Help with BATCH file

    Quote Originally Posted by PeejAvery
    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.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Help with BATCH file

    Quote Originally Posted by dglienna
    ...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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Jan 2007
    Posts
    4

    Re: Help with BATCH file

    Quote Originally Posted by PeejAvery
    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.****.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 (**** 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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured