asp.netusb3gmodemras

DotRas unauthorized access exception when adding phonebook an entry


I am devoloping an application with dotras dll. In the application my main goal is to connect to the internet with 3g USB modem. I am adding my code below :

    RasPhoneBook book = new RasPhoneBook();
    book.Open();
    dialer = new RasDialer();
    dialer.StateChanged += new EventHandler<StateChangedEventArgs>  (dialer_StateChanged);
    RasDevice device = RasDevice.GetDeviceByName("ZTE", RasDeviceType.Modem);
    RasEntry entry = RasEntry.CreateDialUpEntry("MyEntry", "*99#", device);
    entry.EncryptionType = RasEncryptionType.Optional;
    entry.Options.ModemLights = true;
    entry.NetworkProtocols.IP = true;
    entry.NetworkProtocols.Ipx = false;
    book.Entries.Add(entry);
    dialer.PhoneBookPath = book.Path;
    dialer.EntryName = "MyEntry";
    dialer.Dial();

When I tried to add the phonebook my entry it's returning an exception :

UnauthorizedAccessException was Unhandled

The caller does not have required permission to perform the action requested.

I'm new about DotRas. So which permissions does it neeeded to add an entry to the phonebook?

Any ideas?


Solution

  • I have found the answer. The reason why I need to elevate privileges for the application is due to the application opening the All User's profile phone book. This is indicated by my call to book.Open()

    If you encountered a problem like this remember you can always store the phone book next to your application, which will remove the need to elevate permissions.

    The code should be :

               RasPhoneBook book = new RasPhoneBook();
               book.Open(".\\MyAppPhoneBook.pbk");