Page 1 of 1

Open a VPN connection

Posted: Thu Nov 11, 2010 4:18 pm
by frose
Hi,

my WLAN-clients permantely forgets to open the VPN connection before starting my app.

Is it possible to check, if a VPN connection is open and if not, open it via program with the right parameters?

Many thanks in advance

Re: Open a VPN connection

Posted: Sun Nov 14, 2010 2:11 pm
by ADutheil
The function below works with open VPN client. If you use another way to connect to your VPN you might adapt it to fit your needs. The only thing you have to know is the IP address of the VPN. In my case DHCP server returns an IP from the 172.20.20.0/24 net. So I set the cWlan param to "172.20.20.".

FUNCTION ChkVPN
LOCAL nHips := fCreate( "listip.bat" )
LOCAL cBuff := ""
LOCAL lRetu := .F.
LOCAL cWlan := "172.20.20."

fWrite( nHips, "ipconfig >listip.lst" )
fClose( nHips )
ShellExecute( 0, "open", "listip.bat",,, )
IF ( nHips := fOpen( "listip.lst" ) ) > 0
WHILE hb_fReadLine( nHips, @cBuff ) = 0
IF cWlan $ cBuff
lRetu := .T.
EXIT
ENDIF
ENDDO
fClose( nHips )
ELSE
msgStop( "UNABLE TO OPEN FILE listip.LST" )
ENDIF
fErase( "listip.bat" )
fErase( "listip.lst" )
IF !lRetu
msgStop( "VPN NOT CONNECTED!" )
ENDIF
RETURN ( lRetu )

To launch your VPN you can use winexec() function