This project is read-only.

Using DotRas to connect to a vpngate vpn on Windows 10

Dec 29, 2016 at 5:12 AM
I'm trying to use DotRas to establish a VPN connection on my computer. It needs a Pre shared key but I cant find the option to add one when dialing. I'm using DotRas V1.3

This is what I have so far using an example that came with DotRas
Imports System.Net
Imports DotRas

Public Class MainForm
    Public Const EntryName As String = "vpnconnection"
    Private connectionHandle As RasHandle

    Private Sub CreateEntryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateEntryButton.Click
        ' This opens the phonebook so it can be used. Different overloads here will determine where the phonebook is opened/created.

        ' Create the entry that will be used by the dialer to dial the connection. Entries can be created manually, however the static methods on
        ' the RasEntry class shown below contain default information matching that what is set by Windows for each platform.
        'Dim entry As RasEntry = RasEntry.CreateVpnEntry(EntryName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn))
        Dim entry As RasEntry = RasEntry.CreateVpnEntry(EntryName, "", RasVpnStrategy.Default,
                                                        RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn,))
        ' Add the new entry to the phone book.
    End Sub

    Private Sub DialButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DialButton.Click

        ' This button will be used to dial the connection.
        Me.Dialer.EntryName = EntryName
        Me.Dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers)

            ' Set the credentials the dialer should use.
            Me.Dialer.Credentials = New NetworkCredential("vpn", "vpn")

            ' NOTE: The entry MUST be in the phone book before the connection can be dialed.
            ' Begin dialing the connection; this will raise events from the dialer instance.
            Me.connectionHandle = Me.Dialer.DialAsync()

            ' Enable the disconnect button for use later.
            Me.DisconnectButton.Enabled = True
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Dialer_StateChanged(ByVal sender As System.Object, ByVal e As DotRas.StateChangedEventArgs) Handles Dialer.StateChanged
        Me.StatusTextBox.AppendText(e.State.ToString() + Chr(13) + Chr(10))
    End Sub

    Private Sub Dialer_DialCompleted(ByVal sender As System.Object, ByVal e As DotRas.DialCompletedEventArgs) Handles Dialer.DialCompleted
        If (e.Cancelled) Then
        ElseIf (e.TimedOut) Then
            Me.StatusTextBox.AppendText("Connection attempt timed out!")
        ElseIf (e.Error IsNot Nothing) Then
        ElseIf (e.Connected) Then
            Me.StatusTextBox.AppendText("Connection successful!")
        End If

        If (Not e.Connected) Then
            Me.DisconnectButton.Enabled = False
        End If
    End Sub

    Private Sub DisconnectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisconnectButton.Click
        If (Me.Dialer.IsBusy) Then
            ' The connection attempt has completed, attempt to find the connection in the active connections.
            Dim connection As RasConnection = RasConnection.GetActiveConnectionByHandle(Me.connectionHandle)
            If (connection IsNot Nothing) Then
                ' The connection has been found, disconnect it.
            End If
        End If
    End Sub
End Class
I tried using this under CreateEntry- entry.options.UsePreSharedKey = True

but Im getting the error - UsePreSharedKey is not a member of RasOptions

Any help would be much appreciated!