In my application I'm using the rasphone function to connect to vpn's When my application launches it gets all the vpn connections in a combobox using this code.
String f = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Network\Connections\Pbk\rasphone.pbk";
if (System.IO.File.Exists(f))
{
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
if (s.StartsWith("["))
{
char[] MyChar = { ']' };
string NewString = s.TrimEnd(MyChar);
char[] MyChar2 = { '[' };
string NewString2 = NewString.TrimStart(MyChar2);
comboBox1.Items.Add(NewString2);
}
}
}
else
{
MessageBox.Show("PBK File not found.");
}
comboBox1.Sorted = true;
Now my question is how I can also get the phonenumer= section to display in a textbox or label, so I know what the IP is.
A pbk file looks like this (had to delete some rows), the problem is that I have multiple vpn connections in the pbk file so also multiple phonenumer= entries.
[VPN Name of connection]
Encoding=1
PBVersion=3
Type=2
DEVICE=vpn
PhoneNumber= 0.0.0.0 <- ip address I want to display in a label or textbox.
AreaCode=
CountryCode=0
CountryID=0
UseDialingRules=0
Comment=
FriendlyName=
LastSelectedPhone=0
PromoteAlternates=0
TryNextAlternateOnFail=1