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
Open a VPN connection
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
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 + MSVS 10
André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10