This project is read-only.

VB Questions for VPN status

Jun 8, 2009 at 8:57 PM


First, this is a great project and is exactly what I was looking for, thanks for all your work.

I am building my application in VB and what I need it to do is Create Connection > Show Active Connections > Disconnect Selected Connection

Following your Youtube video I was able to get it working and it is opening connections, all the connections were previously created by hand.

I am having difficulty getting a list of active connections so I can display them on the form and then disconnect the connections.

I found this thread about how to do it in C# but I cannot figure out how to do it in VB.

Is there a way to get the connections list and have it output to a text box?


I'm trying to do stuff like this-

txtboxActive.Text = Me.RasDialer1.GetActiveConnections.Item(0).GetConnectionStatistics.ToString

But it is not working. Could you please give a quick example of how to get such information into a text box and then I can figure out the rest?

I'm very much a VB newbie with all this stuff but with an example I should be able to figure out the rest.



Jun 8, 2009 at 9:57 PM
Edited Jun 8, 2009 at 9:57 PM

For Each connection As RasConnection In Me.RasDialer1.GetActiveConnections()


Inside that loop the connection object is a RasConnection and has all the functionality available to it. Using connection.HangUp() would disconnect the connection, the connection.EntryName property contains the name of the connection. The GetConnectionStatistics method you used above retrieves real-time network traffic statistics of that particular connection. Calling ToString on the RasLinkStatistics class would simply return "DotRas.RasLinkStatistics" since the ToString method has not been overridden, and is therefore useless on that particular object.


With this code, you're also assuming that you will always have at least 1 connection active on the machine which poses a lot of issues:

What if there are no active connections? (Your application would crash currently throwing an IndexOutOfRangeException)

What happens if there are 2 connections needed and your connection isn't the first connection returned?

Just some things to think about when you're writing code to interact with the dialer.


Edit: Fixed the casing on a couple keywords.