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
Open a VPN connection
Re: Open a VPN connection
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
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
Regards,
André Dutheil
FWH 13.04 HB 3.2 BCC 5.82 MinGW 4.5.2 MSVS 10
André Dutheil
FWH 13.04 HB 3.2 BCC 5.82 MinGW 4.5.2 MSVS 10