This project is read-only.

[Vista] UnauthorizedAccesException on Ras entry

Nov 12, 2009 at 5:35 PM


i recived this exception executing application on Vista sp1. (On xp it's work fine).  Maybe is UAC that deny access to phone book?

This exception appears when i try to access on phonebook. Can you help me? Or gime some indication to solve this ?

Thanks in advanced to all.

Nov 12, 2009 at 6:02 PM

If disable control user application work..... even if when i create a vpn connection visualize windows where it ask me to choose which kind of network (home,office,public).

How can disable this windows?

Nov 12, 2009 at 6:06 PM

I can only imagine the UAC is what's causing your problems. To test this theory, you can disable the UAC temporarily and test your application. If it in fact is causing the problem you will need to elevate the privileges requested by your application through the manifest file.

That article should help you with the privilege elevation. I haven't tested it myself before, I'm psychotic and keep the UAC disabled on my computer. It's just too much of a pain in the butt during development when you're working with the Win32 APIs directly.

Just out of curiosity, which method on RasEntry caused the exception?

Nov 12, 2009 at 6:10 PM

In response to your second question, you can't disable or bypass it. It's a feature to determine the network and file sharing privileges the connection will use.  What I have told others in the past that encounter that dialog is to only create the connection once. The first time a connection is made Windows prompts the user for what kind of network it is.

If you want to keep the entry hidden from your users so they can't dial it manually, store the entry in a custom phone book. You just need to supply a path to the Open method on RasPhoneBook that isn't in the standard locations Windows looks for. That will prevent it from being shown in the Network Connections window.

Nov 12, 2009 at 6:17 PM

Great Jeff! I love you !!

Now i try to implement you suggestion.

Nov 13, 2009 at 10:02 AM

Jeff i inform you that excpetion was trown  (for first question) when i use entry.Update(); now i have solved it adding manifest to my exe  (with mt.exe........)

This is all right, but now i'm trying to using a "custom" phonebook

if (Directory.Exists(@"c:\testphone"))
        foreach (RasEntry entrycount in rasPhoneBook1.Entries)
          if (entrycount.Name == "L2tpVpn")

if (num_vpn == 0)

          entry = RasEntry.CreateVpnEntry("Tin", SERVER, RasVpnStrategy.L2tpOnly,
           RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn, false));

          entry.DnsAddress = IPAddress.Parse("");

          entry.Options = RasEntryOptions.SpecificNameServers;
          entry.RedialCount = 0;
          entry.ExtendedOptions = RasEntryExtendedOptions.UsePreSharedKey;

when i try to add entrie i recive "RasException" Unable to update phonebook file......  really in this directory file .pbk not exist. How can i create it?

Can you help me?



Nov 13, 2009 at 2:54 PM

Well, you created a directory named the same as your phone book in the same location, you can't do that in Windows.

You're also overwriting any options and extended options that are set within CreateVpnEntry, you need to combine the flags not overwrite them. Use the |= operator.

using System;
using System.IO;

if (Directory.Exists(@"C:\testphone"))

    // Continue with what you need to do.

You need to provide the name of the file, not just the path where you want it. The intellisense should have indicated the full path to the file including file name you wish to open.