This project is read-only.

Pre-shared key with Custom phonebook

Dec 1, 2010 at 10:58 PM

Hi there,

At the moment I have my own phonebook but the problem I'm facing at the moment is with the pre-shared key now it doesnt update

Here is the code I have to create the profile

        Dim pbk As New RasPhoneBook

        Dim entry As RasEntry = RasEntry.CreateVpnEntry(EntryName, ServerIP, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn)
        entry.Options.UsePreSharedKey = True
        entry.UpdateCredentials(RasPreSharedKey.Client, SharedKey)

Still with the code above the pre-shared key doesnt get set

Any advice would be great.

Many Thanks

Dec 2, 2010 at 5:41 AM

I know there were some strange things with credentials in RAS, one of them being around custom phonebooks and their inability to store credentials for all users. Preshared keys may have the same problem, though not confirmed. Have you tried double clicking the phonebook and checking the entry out in the standard Windows interface? You can check the settings to see whether the preshared key has been set in there.

Also, what makes you think the key isn't being set?

Dec 2, 2010 at 1:18 PM

Hi Jeff

The reason I think the key isnt being used is because when i load the phone book with the Windows Interface and then go to Properties the pre-shared key section is empty.

Also any ideas why this is happening

When the VPN is actually connected when i try to Disconnect I get this error

Unhandled exception has occurred in your application

Value Cannot be null

Parameter name: handle

To disconnect I use this

If (Me.Dialer.IsBusy) Then
            Dim connection As RasConnection = RasConnection.GetActiveConnectionByHandle(Me.connectionHandle)
            If (connection IsNot Nothing) Then
            End If
        End If


Many Thanks

Dec 2, 2010 at 11:54 PM

Can you get me the stack trace when the error occurred?

Dec 3, 2010 at 12:58 AM

For the disconnect

If this is what you mean.

System.ArgumentNullException was unhandled
  Message=Value cannot be null.
Parameter name: handle
       at DotRas.Internal.ThrowHelper.ThrowArgumentNullException(String argumentName)
       at DotRas.RasConnection.GetActiveConnectionByHandle(RasHandle handle)
       at DotRas.Samples.CreateAndDialVpnEntry.MainForm.DisconnectButton_Click(Object sender, EventArgs e) in C:\Users\username\Desktop\VPNClient\VPN\MainForm.vb:line 62
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at DotRas.Samples.CreateAndDialVpnEntry.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Dec 3, 2010 at 3:44 AM
Edited Dec 3, 2010 at 4:03 AM

Well obviously you can't try to find a handle without providing the method the handle to find. Handle cannot be a null reference (Nothing in Visual Basic) for the method to work.

Edit: I also ran the exact same code you posted above and had no problem setting the pre-shared key with it.

using DotRas;

RasPhoneBook pbk = new RasPhoneBook();

RasEntry entry = RasEntry.CreateVpnEntry("VPN Connection", "", RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn));

entry.Options.UsePreSharedKey = true;
entry.UpdateCredentials(RasPreSharedKey.Client, "12345");

There's the code I used.

Aug 18, 2012 at 2:58 PM
Edited Aug 18, 2012 at 3:02 PM

I had the same problem, but I solved it:



Dim pbk As New RasPhoneBook

Dim entry As RasEntry = RasEntry.CreateVpnEntry(EntryName, ServerIP, RasVpnStrategy.L2tpOnly, RasDevice.GetDeviceByName("(L2TP)", RasDeviceType.Vpn)

pbk.Entries[0].Options.UsePreSharedKey = true
pbk.Entries[0].UpdateCredentials(RasPreSharedKey.Client, SharedKey)



The solution is in last three lines ;)