Create VPN connections

I am in the need of creating VPN connections in VB6.

I need some help and some code to do the following

On frmConnect, I have a button called cmdConnect . This button will need to dynamically build a vpn connection and then launch a terminal server session. I can connect to the terminal server no problem. It is building the vpn connection. The vpn might not already be created on the machine. So I would lke to dynamically build the vpn connection on the fly. If anyone knows how, please let me know

Mike
iNET45Asked:
Who is Participating?
 
WillEastburyCommented:
Actually i think it would be simpler to add the data to the .pbk if needed ...

backup the users .pbk

open the users pbk and search for "[My VPN]", if you can't find it then append the sample to the file.


then ....

If Shell("RASDIAL.EXE " & Chr(34) & "My VPN" & Chr(34) & " <Username> <Password>") = 0 Then

    ' VPN Connection connected OK !
   
else

msgbox "Error"

End If

Here's a sample .pbk entry for a l2tp vpn connection.... don't forget to replace <Remote IP Address> with the dns / ip for your VPN server..

[My VPN]
Encoding=1
Type=2
AutoLogon=0
UseRasCredentials=1
DialParamsUID=2060109
Guid=354FA20BC80D554E9751DD8E57F2314F
BaseProtocol=1
VpnStrategy=2
ExcludedProtocols=0
LcpExtensions=1
DataEncryption=256
SwCompression=1
NegotiateMultilinkAlways=0
SkipNwcWarning=0
SkipDownLevelDialog=0
SkipDoubleDialDialog=0
DialMode=1
DialPercent=75
DialSeconds=120
HangUpPercent=10
HangUpSeconds=120
OverridePref=15
RedialAttempts=3
RedialSeconds=60
IdleDisconnectSeconds=0
RedialOnLinkFailure=0
CallbackMode=0
CustomDialDll=
CustomDialFunc=
CustomRasDialDll=
AuthenticateServer=0
ShareMsFilePrint=1
BindMsNetClient=1
SharedPhoneNumbers=0
GlobalDeviceSettings=0
PrerequisiteEntry=
PrerequisitePbk=
PreferredPort=VPN3-0
PreferredDevice=WAN Miniport (L2TP)
PreferredBps=0
PreferredHwFlow=1
PreferredProtocol=1
PreferredCompression=1
PreferredSpeaker=1
PreferredMdmProtocol=0
PreviewUserPw=1
PreviewDomain=0
PreviewPhoneNumber=0
ShowDialingProgress=1
ShowMonitorIconInTaskBar=1
CustomAuthKey=-1
AuthRestrictions=608
TypicalAuth=2
IpPrioritizeRemote=1
IpHeaderCompression=0
IpAddress=0.0.0.0
IpDnsAddress=0.0.0.0
IpDns2Address=0.0.0.0
IpWinsAddress=0.0.0.0
IpWins2Address=0.0.0.0
IpAssign=1
IpNameAssign=1
IpFrameSize=1006
IpDnsFlags=0
IpNBTFlags=1
TcpWindowSize=0
UseFlags=0
IpSecFlags=0
IpDnsSuffix=

NETCOMPONENTS=
ms_server=1
ms_msclient=1

MEDIA=rastapi
Port=VPN3-0
Device=WAN Miniport (L2TP)

DEVICE=vpn
PhoneNumber=<Remote IP Address>
AreaCode=
CountryCode=44
CountryID=44
UseDialingRules=0
Comment=
LastSelectedPhone=0
PromoteAlternates=0
TryNextAlternateOnFail=1

0
 
WillEastburyCommented:
If you are using the MS VPN Client built in to windows, you can launch it with RASDial.exe  :-

USAGE:
        rasdial entryname [username [password|*]] [/DOMAIN:domain]
                [/PHONE:phonenumber] [/CALLBACK:callbacknumber]
                [/PHONEBOOK:phonebookfile] [/PREFIXSUFFIX]

        rasdial [entryname] /DISCONNECT

        rasdial

If you need to build the connection on the fly (Before you launch it !), then you need to modify the current users phonebook.pbk file (C:\Documents and Settings\All Users\Application data\Microsoft\Network\Connections\Pbk\rasphone.pbk).

You can do this by first checking if the connection is there, if not then append your connection to the file ...

(You should be able to copy the information you need from a correctly configured .pbk file on your machine.)

Hope this will help, if you need more then let me know...

Thanks,
Will

0
 
iNET45Author Commented:
Are you saying to backup the .pbk


Add the entry
Check the .pbk

Copy the new contents out.

Replace the .pbk with the original and start pounding away?

Do you have a sample in vb6 to do this?

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
WillEastburyCommented:
On the users machine :-

1. Try to dial the vpn connection (otherwise known as a RAS connectoid)

Private Sub Command1_Click()

If Shell("RASDIAL.EXE ""T-Mobile GPRS""") = 0 Then

    ' VPN Connection connected OK !
   
Else

    ' VPN CONNECTION DIDN'T CONNECT, LET'S CREATE IT!

End Sub

2. if this fails then you need to create it!

The .pbk is in ini file format. You can either use the ini creation method described by me above (copy the chunk out of your machines ini file that already has the connection created, or look here for a pure vb6 / api version to modify  !

     http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10128291.html

Also, this should help you .....

    http://www.carterszoo.com/connectoid_code.html

Thanks,
Will Eastbury

0
 
iNET45Author Commented:
I'll take a look later today and let you know my results.

The link for bobsewell's page is bad on the above link.. Ugh.. I will have to play and poke.
0
 
iNET45Author Commented:
Is the GUID going to be Unique?
0
 
WillEastburyCommented:
One would expect it would be a unique assigned number per machine . However, having said that maybe it would be more logical for you to search for the GUID, as well as the name, when checking to see if the connection exists.

Give it a try and see what you get.

What I would advise you to do, is not to try and use my posted example file, create the VPN connection on your pc and test it works, then copy the part of your pbk assocated with that connection into another machine's pbk and try it.

If that works, then you have a template entry to add to a pbk file on ANY machine, which will make your life MUCH easier!

Thanks,
Will

0
 
iNET45Author Commented:
True.. I'll post results later or tommorow.
0
 
iNET45Author Commented:
Will.. Do you have any code to check and append to the pbk file?
0
 
WillEastburyCommented:
I don't have example code off hand, but can help with the steps :-

Check the connection does not exist ...

       Load in the file into a string variable and do an instr() test to see if it exists.

If you stored the connection to copy in in a file then you could do a dos copy command on it

      Shell("copy backedupphonebook.pbk + myphonebookentry.pbk phonebook.pbk")

Either that or store it in a string variable and append it to the file using the fso commands.
0
 
WillEastburyCommented:
Would suggest that since the user has not responded, I have provided enough assistance for them to resolve their problem.

I think I should be given the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.