How to judge the PPPoE Entry is exist or not ?

Jun 20, 2010 at 3:03 AM
Edited Jun 20, 2010 at 3:10 AM

 

this is my click event    
Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Connect.Click
        Me.AllUsersPhoneBook.Open()
        Dim PhoneNumber As String = " "
        Dim entry As RasEntry = RasEntry.CreateDialUpEntry(EntryName, PhoneNumber, RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE))
        Me.AllUsersPhoneBook.Entries.Add(entry)
        Me.Dialer.EntryName = EntryName
        Me.Dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers)
        Try
            Me.Dialer.DialAsync(New NetworkCredential("user", "pass"))
        Catch ex As Exception
        End Try
    End Sub

 

i want to realize that when i click the button the program will check the PPPoE Entry is exist or not.

if the PPPoE is exist then dial,else creat entry and dial.

Hope to your help deepin!!!

Coordinator
Jun 20, 2010 at 3:25 AM

You can always just use the Contains method on the phone book entries to check whether the entry exists prior to adding it.

If Not Me.AllUsersPhoneBook.Entries.Contains(EntryName) Then
    Dim entry As RasEntry = RasEntry.CreateDialUpEntry(EntryName, PhoneNumber, RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE)
    Me.AllUsersPhoneBook.Entries.Add(entry)
End If

 

Jun 20, 2010 at 3:44 AM

Thx for your quick response.i get it

Jun 20, 2010 at 4:31 AM

Dim entry As RasEntry = RasEntry.CreateDialUpEntry(EntryName, PhoneNumber, RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE))

oops.....it can't create a PPPoE entry via PAP protocol.

Jun 20, 2010 at 4:57 AM

 

            Dim entry As New RasEntry(EntryName)
            entry.Device = RasDevice.GetDeviceByName("(PPPOE)", RasDeviceType.PPPoE, False)
            entry.EntryType = RasEntryType.Broadband
            entry.FramingProtocol = RasFramingProtocol.Ppp
            entry.NetworkProtocols = RasNetworkProtocols.IP
            entry.RedialCount = 3
            entry.RedialPause = 60
            entry.PhoneNumber = " "
            entry.Options = RasEntryOptions.RemoteDefaultGateway Or _
                RasEntryOptions.ModemLights Or _
                RasEntryOptions.SecureLocalFiles Or _
                RasEntryOptions.RequirePap Or _
                RasEntryOptions.PreviewUserPassword Or _
                RasEntryOptions.ShowDialingProgress Or _
                RasEntryOptions.RequirePap Or _
                RasEntryOptions.RequireChap Or _
                RasEntryOptions.RequireMSChap2
            entry.ExtendedOptions = RasEntryExtendedOptions.SecureFileAndPrint Or _
                RasEntryExtendedOptions.SecureClientForMSNet Or _
                RasEntryExtendedOptions.DoNotNegotiateMultilink Or _
                RasEntryExtendedOptions.DoNotUseRasCredentials Or _
                RasEntryExtendedOptions.Internet Or _
                RasEntryExtendedOptions.DisableNbtOverIP Or _
                RasEntryExtendedOptions.ReconnectIfDropped
            Me.AllUsersPhoneBook.Entries.Add(entry)

i use this code fix the bug. 

RasEntryOptions.RequirePap Or _

 

Feb 13, 2011 at 4:28 PM

Hi guys, we have a problem implementing Jeff's suggested way to check if a dialer exists, using C#:

//RasEntry vpnObj = RasEntry.CreateVpnEntry(EntryName, LNS, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));

if (this.AllUsersPhoneBook.Entries.Contains("TripleC_VPN"))
            {
                this.CreateEntryButton.Enabled = false;
            }

(We tried feeding it the vpnObj as well).

 

Problem is, the condition check always skips and returns false regardless whether the VPN exists or not.

 

For now we have a workaround of catching the exception when the user tries to click button to create the VPN but it already exists, but we want the above more elegant solution to work :)

Coordinator
Feb 13, 2011 at 8:25 PM

Are you sure the phone book you're checking for the entry in is in fact the phone book the entry exists in? There are two phone books in use by Windows even though they're aggregated into one in the Network Connections window.

Feb 13, 2011 at 8:47 PM
jeff_winn wrote:

Are you sure the phone book you're checking for the entry in is in fact the phone book the entry exists in? There are two phone books in use by Windows even though they're aggregated into one in the Network Connections window.

Thank you Jeff! indeed I had to do  this.AllUsersPhoneBook.Open(); and then it works :)