?
Solved

Create VPN connections

Posted on 2006-04-08
14
Medium Priority
?
1,059 Views
Last Modified: 2008-10-22
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
0
Comment
Question by:iNET45
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:WillEastbury
ID: 16415423
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
 

Author Comment

by:iNET45
ID: 16417838
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
 
LVL 3

Expert Comment

by:WillEastbury
ID: 16418125
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:iNET45
ID: 16418199
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
 
LVL 3

Accepted Solution

by:
WillEastbury earned 1000 total points
ID: 16418245
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
 

Author Comment

by:iNET45
ID: 16418430
Is the GUID going to be Unique?
0
 
LVL 3

Expert Comment

by:WillEastbury
ID: 16418523
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
 

Author Comment

by:iNET45
ID: 16418661
True.. I'll post results later or tommorow.
0
 

Author Comment

by:iNET45
ID: 16422712
Will.. Do you have any code to check and append to the pbk file?
0
 
LVL 3

Expert Comment

by:WillEastbury
ID: 16424608
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
 
LVL 3

Expert Comment

by:WillEastbury
ID: 16680645
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month16 days, 4 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question