Open a VPN connection

Open a VPN connection

Postby frose » Thu Nov 11, 2010 4:18 pm

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
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Open a VPN connection

Postby ADutheil » Sun Nov 14, 2010 2:11 pm

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
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 75 guests