VPN Connection Question

Mar 17, 2009 at 4:58 AM
I have a problem with one RasEntry param when I creates new entry.
So I can't assign Device
entry = new RasEntry(constant.VPN_CONNECTION_NAME);
entry.Device = (and here do not know what to do)
I already tried get all devices and in a loop check what I need and then assign but without success (((
Mar 17, 2009 at 12:48 PM
Typically with VPN connections you need to use whichever WAN Miniport driver you're using. For PPTP VPN connections you'll want to use the PPTP driver, and if you're creating an L2TP connection you'll need the L2TP driver. Typically you'll want to set this value to the L2TP Miniport driver unless you're using the PPTP first or PPTP only VPN strategy.
Mar 17, 2009 at 1:58 PM
Ok, I got it.
But if u can, please give an example code how can I do that.
Because I tried set params directly, but without success.
I eager to get an example )))
Mar 17, 2009 at 2:21 PM
Well, that really depends on your application and how you intend to get the information about which device you want to use. Whether you'll put it into a configuration file somewhere, or if you want to have a user select the device to use for the connection. Also, I'm not sure what you'll see in the device name or type fields of the RasDevice object, which is why I didn't hard-code which device should be used. The string I've used below may be completely different on your machine, this is just an example:

RasDevice useDevice = null;
foreach (RasDevice device in RasDevice.GetDevices())
    if (string.Compare("WAN Miniport (L2TP)", device.DeviceName, true) == 0)
        useDevice = device;

I've been debating about exposing the constructor for the RasDevice class, I'm just concerned that doing so could corrupt machines since people may start creating devices that aren't actual devices on the machine.

If you're using RC1 from the releases tab (which I uploaded earlier this morning) you'll have access to the RasEntryHelper class, which should assist you in creating new entries manually.

RasEntry myEntry = RasEntryHelper.CreateVpnEntry("My New Entry", "", RasVpnStrategy.Default, useDevice);

That will build a new VPN entry with all of the default settings. Just make sure you change the server address. If you would rather create the entire entry manually, you can do that as well. Though it will take a lot more effort than if you simply used the helper class I've exposed.
Mar 17, 2009 at 4:56 PM
Oh, good! Thanks a lot!
I'll try this way u proposed.
And I will update DotRas to RC1 to try out helper method)))
Thanks a lot!
Mar 17, 2009 at 5:36 PM
One question...

this device "WAN Miniport (L2TP)" is language-dependent.. for example, in Spanish, this device is called "Minipuerto WAN (L2TP)". If I want to develelop an application to be used in different countries, this is a little problem...

Are there any way to detect this name?

Thanks :)
Mar 17, 2009 at 6:06 PM
Edited Mar 17, 2009 at 6:15 PM
Yeah I made a bit of an assumption that "WAN Miniport (L2TP)" wouldn't transfer between languages. That's the entire reason why I didn't hard-code that information in the application.

"Are there any way to detect this name?"

No, but you can use the globalization capabilities of .NET to store the strings for each language you want your application to support, or make the user select which WAN driver to use. Don't forget that SSTP (Secure Socket Tunneling Protocol) is available in Vista as another VPN protocol. Globalization is out of the scope of this project, so you'll have to do the research for that on your own if you want to use it.

Unfortunately the RasEnumDevices API doesn't provide any other information back to the caller than the device name and type.

Edit: I probably should have been a bit more specific when I said no. What I mean is the DotRas assembly doesn't have any other information available to it besides the device name and type. I do know that WMI can be used to query hardware information, but I do not know enough about it to tell you how. I'm sure you're well aware that storing strings is generally a bad idea, since the information can change. If Microsoft ever decided to change the name we're seeing the applications would all break.

The only thing I can think of would be to get the list of RAS capable devices (which are returned from RasDevice.GetDevices) and query WMI to see which device you should be using for the entry.
Mar 17, 2009 at 7:55 PM
I'm hoping that one of you are using a non-english version of Windows for this:

When you're looking at the collection of devices returned from RasDevice.GetDevices, what is the DeviceType property showing for the "Minipuerto WAN (L2TP)" device?

I'm hoping it's "vpn".
Mar 18, 2009 at 10:20 AM
Yes, I'm using a Spanish version of my XP and yes, DeviceType returned is "vpn":

Name: Paralelo directo.          Type: parallel.
Name: Minipuerto WAN (L2TP).     Type: vpn.
Name: Minipuerto WAN (L2TP).     Type: vpn.

Name: Minipuerto WAN (PPTP).     Type: vpn.
Name: Minipuerto WAN (PPTP).     Type: vpn.
Name: Minipuerto WAN (PPPOE).    Type: pppoe.

I'll work on this...
Mar 18, 2009 at 12:53 PM
Hi jeff,
this worked:

      private static RasDevice GetPptpDevice(System.Collections.ObjectModel.ReadOnlyCollection<RasDevice> collDevice)
            foreach (RasDevice rd in collDevice)
                if (rd.Name.Contains("PPTP")) return rd;
            return null;

I supose device name contains "PPTP" or "L2TP" in all languages...

Thanks a lot! :)

I'm working on set the WINS server. My code is:

RasEntry reConnection = RasEntryHelper.CreateVpnEntry("name", "x.x.x.x", RasVpnStrategy.PptpOnly, device);
reConexion.WinsAddress = IPAddress.Parse("y.y.y.y");

Then I add this connection to phonebook, but the it has WINS server in blank. Do you know why..?

Mar 18, 2009 at 1:54 PM
Well I checked the code on my end and all of it looks fine. I checked the SDK and it looks like those members are ignored unless the SpecificNameServers option has been set for the entry.

reConexion.Options |= RasEntryOptions.SpecificNameServers;

That should do the trick. I'll make a note to add that into my help file for those properties.
Mar 18, 2009 at 3:47 PM
Edited Mar 18, 2009 at 4:07 PM
Thank you Jeff. That works fine :)

I want append DNS suffix [2], and not to be DNS suffix to the connection [1].
With the property:
reConexion.DnsSuffix = "mydomain.net";
I can set [1], but I didn't be able to set [2]...

Are there any way to do this?

Thank, and sorry too much questions!

net configure

Edit: I try insert an image here. The link is http://lh6.ggpht.com/_xaZrtwuhivE/ScEWEcp7oPI/AAAAAAAAAK8/uGK9_8P_YZI/net2.JPG
Mar 18, 2009 at 5:56 PM
Ok, this item affects to all connections, not only VPNs, I will not change it ;)

Thanks Jeff.

Alberto Fojo
Mar 18, 2009 at 6:14 PM
I don't mind helping. Getting used to working with the RAS in Windows is complicated.

If you have any other questions, don't hesitate to ask.
Nov 26, 2010 at 2:35 PM

I have exactly the same problem of juerisnai and I would like to set up a DNS address as described in the picture above (in number 2).

Is this possible with DotRas ?

Thanks !

Nov 26, 2010 at 3:06 PM
Edited Nov 26, 2010 at 3:07 PM

The problem with that section of TCP/IP settings is that it's not tied in RAS, it's somewhere else in Windows. Even though it looks like you can change those settings for each specific entry in a phone book, you can't.

This is indicated by the bit of text directly above that area: "The following three settings are applied to all connections with TCP/IP enabled. For resolution of unqualified names:"

Unfortunately since it's not directly in the RAS API, it hasn't been implemented in the project. If you manage to find the APIs to set the information, let me know and I might be able to get it into the project.