Pbk file missing, and how to auto dial?

Apr 7, 2009 at 5:55 PM
I've noticed that if you open a RasPhoneBook and the path "C:\\Documents and Settings\\All Users\\Application Data\\Microsoft\\Network\\Connections\\Pbk\\rasphone.pbk" does not exist, it cannot create a new entry.

However, if I create the file and then start the process it works.  Any ideas why?  I tried disposing the phonebook, calling File.Create(), and creating a new phonebook and got the same result.  It didn't work until I ran the process again.

Also how do you set up the connection to Auto-Dial?  Do you have a quick example of using the RasAutoDialManager?
Coordinator
Apr 7, 2009 at 6:20 PM
I've noticed that if you open a RasPhoneBook and the path "C:\\Documents and Settings\\All Users\\Application Data\\Microsoft\\Network\\Connections\\Pbk\\rasphone.pbk" does not exist, it cannot create a new entry.

I actually spotted that same bug myself earlier this week and fixed it, I also added a unit test to ensure this requirement is met. You'll just need to download the latest source code and compile it yourself to fix it (or wait until the next release). For that location you shouldn't need to specify the entire path of the phone book. That's the phone book in the all user's profile, which is defaulted to open by simply calling Open();

"Also how do you set up the connection to Auto-Dial?  Do you have a quick example of using the RasAutoDialManager?"

To be perfectly honest, I don't know how the auto dial system works. I believe it's based on a DNS name or IP address that when used forces Windows to connect to the entry. The component was written and it does function correctly, I just don't know if Windows is going to work the way you expect it to. So just be aware, you might be the first person to try and use that component.

using (RasAutoDialManager manager = new RasAutoDialManager())
{
    RasAutoDialAddress address = new RasAutoDialAddress("Your Address Here");
    address.Entries.Add(new RasAutoDialEntry(1, "Your Connection Name"));

    manager.Update(address);
}

That will create a new auto-dial address and add it to the list in Windows.
Apr 7, 2009 at 7:59 PM
Is a better solution to call it to connect programmatically?

Use:

RasDialer dialer = new RasDialer();
dialer.EntryName = CONNECTION_NAME;
dialer.Dial();

...and then I guess call HangUp() at some point?

If I was writing a quick tray icon that connects, you think it would be best to call Dial() and HangUp() for the life of the program?

What would cause it to disconnect?  Sorry if it's a lot of questions.
Coordinator
Apr 7, 2009 at 8:38 PM
Well that depends on what you're trying to do with your application, which architecting your software is out of the scope of this project.

I would use DialAsync more than Dial when connecting. You're going to cause your application to hang until the connection is successful and you have no timeout functionality if your application sits there for 30 seconds trying to connect.

Lots of things can cause a connection to disconnect... network cable unplugged, a goat ate your router, etc. If you're wanting to handle disconnecting a connected entry, you'll use the dialer.GetActiveConnections method, finding the entry you want to disconnect, and calling HangUp on the instance. If you want to know when a connection's state has changed outside of the application controlling it you'll want to use the RasConnectionWatcher component.