The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,466 other followers

Batch file to “Keep Alive” a CMAK generated VPN connection in Windows 7

Posted by jpluimers on 2012/05/08

Some clients generate their VPN connection settings using the CMAK (Connection Manager Administration Kit). Apart from the cumbersome way to support both x86 and x64 at the same time, they usually add in some kind of time-out feature, and often route the whole network over the VPN to just host a couple of dozen machines. Having done most of my VPN connections by hand, and automating them using rasdial to dial these from the commandline, I also found out the hard way that you cannot use rasdial for CMAK generated VPN connections: it will give you the error “This function is not supported on this system.”. The funny thing is: you can disconnect using rasdial. Luckily, the far less well documented rasphonedoes work for dialing. The batch file below uses a few tricks, and you can set the parameters in the top of the batch file.

Have fun with it!
@echo off
    setlocal enableextensions
    :: we use for wait, see
    set WaitIP=
    :: usually from a private range: 192.168.*.*, 172.16-31.*.*, 10.*.*.*
    set PingWaitMilliseconds=1000
    set LoopWaitSecondsPlus1=31
    set RasDialName=CMAK VPN NAME

    echo Keep-alive: to keep connected to "%RasDialName%", do not close this window
    :: check if connection is still alive
    ping %CheckIP% -n 1 -w %PingWaitMilliseconds% > nul && goto :showAlive
    ping %CheckIP% -n 1 -w %PingWaitMilliseconds% > nul && goto :showAlive
    echo dead at %date% %time%: "%RasDialName%" :(
    rasdial "%RasDialName%" /disconnect
::    rasdial "%RasDialName%" || goto :noDial
:: rasdial fails on Vista and Windows 7 with the message "This function is not supported on this system." on CMAK generated VPN connections
:: rasdial is able to disconnect these sessions. rasphone is able to dial them.
    rasphone -d "%RasDialName%" || goto :noDial
    echo dialed at %date% %time%: "%RasDialName%" :(
    goto :checkLoop

    echo dial failed at %date% %time%: "%RasDialName%" :(
    goto :disconnect

    echo alive at %date% %time%: "%RasDialName%"
    ping -n %LoopWaitSecondsPlus1% %WaitIP% > mul
    goto :checkLoop


One Response to “Batch file to “Keep Alive” a CMAK generated VPN connection in Windows 7”

  1. […] About a year and a half ago, I wrote about a Batch file to “Keep Alive” a CMAK generated VPN connection in Windows 7. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: