This project is read-only.

recreate an VPN entry with another settings

Oct 31, 2009 at 5:45 PM

Hi I'm using this code to create an VPN entry.

I need to be able to recreate an entry with another settings (server/user & pass).

When I'm trying to add entry second time I get this error.


System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException
   at System.Collections.Generic.Dictionary<System.String,DotRas.RasEntry>.Insert
   at System.Collections.ObjectModel.KeyedCollection<System.__Canon,System.__Canon>.AddKey
   at System.Collections.ObjectModel.KeyedCollection<System.String,DotRas.RasEntry>.InsertItem
   at System.Collections.ObjectModel.Collection<System.__Canon>.Insert
   at DotRas.RasEntryCollection.InsertItem
   at DotRas.Design.RasCollection<System.__Canon>.Add
   at DotRAS.MainForm.Button1Click in d:\VPN\DotRAS\DotRAS\MainForm.cs:line 48
   at System.Windows.Forms.Control.OnClick
   at System.Windows.Forms.Button.OnClick
   at System.Windows.Forms.Button.OnMouseUp
   at System.Windows.Forms.Control.WmMouseUp
   at System.Windows.Forms.Control.WndProc
   at System.Windows.Forms.ButtonBase.WndProc
   at System.Windows.Forms.Button.WndProc
   at ControlNativeWindow.OnMessage
   at ControlNativeWindow.WndProc
   at System.Windows.Forms.NativeWindow.DebuggableCallback
   at ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop
   at ThreadContext.RunMessageLoopInner
   at ThreadContext.RunMessageLoop
   at System.Windows.Forms.Application.Run
   at DotRAS.Program.Main in d:\VPN\DotRAS\DotRAS\Program.cs:line 27




string host = cmb.Text;
            RasEntry entry = RasEntry.CreateVpnEntry(EntryName, host, RasVpnStrategy.PptpOnly,
            RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));

              System.Net.CredentialCache.DefaultNetworkCredentials.UserName = textBox1.Text;
              System.Net.CredentialCache.DefaultNetworkCredentials.Password = textBox2.Text;

            //entry.Options = RasEntryOptions.PreviewUserPassword;
            entry.Options = RasEntryOptions.ShowDialingProgress;
            entry.Options |= RasEntryOptions.NetworkLogOn;
            entry.Options |= RasEntryOptions.RemoteDefaultGateway;
            entry.Options |= RasEntryOptions.ModemLights;
            entry.Options |= RasEntryOptions.SoftwareCompression;




Nov 1, 2009 at 4:05 AM

Are you sure the entry you are adding does not already exist in the phone book you've opened? The entry names must be unique, and that exception would only be thrown if that entry is already existing.

Nov 1, 2009 at 8:16 AM



No, I'm not sure, and I know that this entry already exist.

How can I just update an existing entry ?

I need  to be able to change host, user/pass, connection type: PPTP/L2TP to the existing entry

Nov 1, 2009 at 7:04 PM
DotRas.RasPhoneBook pbk = new DotRas.RasPhoneBook();

DotRas.RasEntry entry = pbk.Entries[EntryName];

// Set your options you want to update on the entry here.


If you are trying to update the credentials saved to an entry, you need to use the UpdateCredentials method on RasEntry since that the credentials are not stored on the entry due to security concerns. If you are trying to save the credentials for all users, you will need to use the WINXP or higher build type along with the UpdateCredentials method that takes an overload indicating to store the credentials for all users.

Nov 2, 2009 at 2:34 PM
Edited Nov 2, 2009 at 2:34 PM

Hi Jeff,


Thank you, I think this is what I need.

contact me if you need free US/UK VPN :)