This project is read-only.

if pppoe entry created don't create it again

Feb 7, 2014 at 12:41 AM
I am in my Project making PPPOE ,, I want to make when i click on button1 if there is no broadband entry , create one , and if there is entry skip the create entry and dial directly
Imports System.Net
Imports System.Net.NetworkInformation
Imports DotRas
Imports Microsoft.Win32

Public Class Form1
    Public Entry As RasEntry = RasEntry.CreateBroadbandEntry("BIDO8597", RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE))
    Private connectionHandle As RasHandle

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.RasPhoneBook1.Open(RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User))
        RasPhoneBook1.Entries.Clear()
        Me.RasPhoneBook1.Entries.Add(Entry)
        RasDialer1.Credentials = New NetworkCredential(TextBox1.Text.ToString(), TextBox2.Text.ToString())
        RasDialer1.EntryName = "BIDO8597"
        RasDialer1.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User)
        Try
            Me.RasDialer1.Credentials = New NetworkCredential(TextBox1.Text.ToString(), TextBox2.Text.ToString())
            Me.connectionHandle = Me.RasDialer1.DialAsync()
        Catch ex As Exception
            Me.TextBox3.AppendText(ex.ToString())
            '  Eventstxt.AppendText(ex.Message.ToString & Chr(10))
            'Eventstxt.AppendText(ex.ToString & Chr(10))
        End Try
        Me.Button1.Enabled = False

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If (RasDialer1.IsBusy) Then
            RasDialer1.Dispose()
        Else
            Dim Mypbk = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User).ToString()
            Dim MyConn As RasConnection = RasConnection.GetActiveConnectionByName("BIDO8597", Mypbk)
            If (MyConn IsNot Nothing) Then
                MyConn.HangUp()
                'Eventstxt.AppendText("Disconnected on User Request!")
            End If
        End If
        Me.TextBox3.Clear()
        Me.TextBox3.AppendText("Disconnected")
        Me.Button1.Visible = True
        Me.Button2.Visible = False
        Me.Button1.Enabled = True
    End Sub

    Private Sub RasDialer1_StateChanged(sender As Object, e As StateChangedEventArgs) Handles RasDialer1.StateChanged
        Me.TextBox3.AppendText(e.State.ToString() + Chr(13) + Chr(10))
    End Sub

    Private Sub RasDialer1_DialCompleted(sender As Object, e As DialCompletedEventArgs) Handles RasDialer1.DialCompleted
        If (e.Cancelled) Then
            Me.TextBox3.AppendText("Cancelled!")
        ElseIf (e.TimedOut) Then
            Me.TextBox3.AppendText("Connection attempt timed out!")
        ElseIf (e.Error IsNot Nothing) Then
            Me.TextBox3.AppendText("Connection Error")
            Me.Button1.Enabled = True
        ElseIf (e.Connected) Then
            Me.TextBox3.AppendText("Connection successful!")
        End If
        If (e.Connected) Then
            Button1.Visible = False
            Button2.Visible = True
        End If
    End Sub
Apr 8, 2014 at 8:16 AM
Edited Apr 8, 2014 at 8:16 AM
   Me.phonebook.Open()
    Dim entry As RasEntry = RasEntry.CreateBroadbandEntry(EntryName, RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE))

    Dim phonebook As New RasPhoneBook
    phonebook.Open()

    If phonebook.Entries.Contains(EntryName) Then
        Dim conn As RasConnection = RasConnection.GetActiveConnectionByName(EntryName, phonebook.Path)
        If conn IsNot Nothing Then
            conn.HangUp()
        End If
        phonebook.Entries.Remove(EntryName)
    End If
    'add entry setting connecting
    phonebook.Entries.Add(entry)
try this code :D