Create VPN connection

Mar 13, 2009 at 11:52 AM
Hi!
First, contratulations for your job! It's amazing!
Second, I want to create a VPN connection programaticaly using dotRas.dll, but I couln't...

Can you help me?

Regards,

Alberto Fojo


Coordinator
Mar 13, 2009 at 3:14 PM
Edited Mar 13, 2009 at 3:18 PM
Creating entries from scratch can be pretty complicated. My suggestion what you should do, create a connection using Windows and then look at all of the settings which it set for you with the RasPhoneBook object, and write them down. Then create a new RasEntry object with those same settings, and add it to the RasPhoneBook you opened.

RasPhoneBook pbk = new RasPhoneBook();
pbk.Open();
RasEntry entry = pbk.Entries["Your Connection Name Here"]; // Make sure you change this!
Make sure you change "Your Connection Name Here" with the entry you just created in Windows.

Depending on whether the entry you created was in the All Users profile or the Current Users profile, you may or may not want to pass true into the overloaded Open method. Write down the entry settings from the entry object you retrieved above.

RasEntry entry = new RasEntry("New VPN Connection");
// Setup the entry the same as the settings you wrote down here.
pbk.Entries.Add(entry);
As soon as you add the entry into the collection, the connection will be available for use from the phone book.
Mar 13, 2009 at 3:37 PM
Many thanks!

I try to do that, and in setup...
// Setup the entry the same as the settings you wrote down here.
... I try to configure to VPN sets DHCP and not to set the IP and DNS... but if I let null on these fields, it doesn't work.

I'll working on it!

(sorry my English!)
Coordinator
Mar 13, 2009 at 3:42 PM
Ah, I think I know why. I've got a helper class that assists with transforming the IPAddress class into the struct that needs to be passed into the API. I'll pull out the null check and just return an empty struct if nothing is passed into it.
Coordinator
Mar 13, 2009 at 3:48 PM
I've made the change with the changeset I just checked in to allow null IP and DNS addresses, just grab the changeset and compile it and it'll be fine.

If you find anything else that seems strange, let me know!