This project is read-only.

VPN Connection Question

Apr 20, 2009 at 10:23 AM
Before creating a PPTP connection, I need to create a PPPOE connection. I did check 'Dial another connection first' in the dialog box.
What should I do to RasDialer first cteated it?
Apr 20, 2009 at 4:32 PM
I'm not 100% sure what you're asking here, so I'll do my best to get it right.

It sounds like you're trying to connect to a PPPOE connection prior to connecting to a VPN connection. There are a few ways to go about doing this.

1) You can set the default internet connection for the machine so it always dials your PPPOE connection prior to connecting to anything.
2) You can have your VPN connection setup to dial another connection (being your PPPOE connection) prior to connecting to that specific entry.
3) Use the RasDialer component to dial your PPPOE connection and once it has completed, use that component to connect to your VPN connection.

The first two would require less code since you'd simply need to change the RasEntry to add support for dialing another entry, or use the RasAutoDialManager component to set the default internet connection. For the 3rd scenario a simple example would be something like:

using (RasDialer dialer = new RasDialer())
{
    dialer.EntryName = "Your PPPOE Connection";
   
    try
    {
        dialer.Dial();

        dialer.EntryName = "Your VPN Connection";

        try
        {
            dialer.Dial();
        }
        catch (Exception)
        {
        }
    }
    catch (Exception)
    {
    }
}

The above example will dial the connection synchronously so if you're using it on a Windows Forms application from the main thread your UI is going to freeze until the connection attempt finishes. I don't know what your application is doing, but I would use the DialAsync method to prevent the UI from freezing if at all possible.
Apr 20, 2009 at 6:18 PM
Thanks for reply, but i am used something like this:
Build project with condition compilation symbol WINXPSP2

private static RasConnectionResult ConnectWithPrerequisitesInternal(String connectionName, String bookPath, NetworkAuthority auth, Int32 timeout)
{
    RasConnectionResult = new RasConnectionResult (RasConnectionResultType.Success, String.Empty, 0);
    RasEntry entry = GetBookEntry(connectionName, bookPath);
    if (entry != null)
    {
         if (!String.IsNulOrEmty(entry.PrerequisiteEntryName)  &&
             !String.IsNulOrEmty(entry.PrerequisitePhoneBook))
         {
             result = ConnectWithPrerequisitesInternal(entry.PrerequisiteEntryName, entry.PrerequisitePhoneBook, null, timeout) ;
         }
         if (result.ResultType != RasConnectionResultType.Error)
         {
             result = ConnectInternal(connectionName, bookPath, auth, timeout);
         }
    }
    else
    {
         result = new RasConnectionResult (RasConnectionResultType.Error, String.Format("Can't found entry '{0}' at the book '{1}'", connectionName, bookPath), 0);
    }
    return result;
}
Apr 20, 2009 at 7:49 PM
Since you're setting the pre-requisite entry information you don't need to dial the prerequisite manually. You've effectively done scenario 2 I described in my earlier post. That should automatically be performed by Windows whenever you try to dial that connection.
Apr 21, 2009 at 6:21 AM
I was test connection without this code. Windows was not performed prerequsite connection.
Apr 21, 2009 at 2:01 PM
Well, not sure what to tell you then. I checked the RasEntry structure in the MSDN documentation and it doesn't mention anything about needing to set any options on the entry to activate it.

"szPrerequisitePbk

Note  Supported on Windows XP or later

Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file. This phone-book file contains the entry specified by the szPrerequisiteEntry member. This member is used only for VPN connections.

szPrerequisiteEntry

Note  Supported on Windows XP or later

Pointer to a null-terminated string that specifies a phone-book entry. This entry should exist in the phone-book file specified by the szPrerequisitePbk member. The szPrerequisteEntry member specifies an entry that RAS dials prior to establishing the connection specified by this RASENTRY structure. This member is used only for VPN connections."

This information can be found http://msdn.microsoft.com/en-us/library/aa377274(VS.85).aspx

What happens when you try to dial the connection through the network connections window? If the prerequisite is connected before the entry you're trying to dial I must have to perform that functionality myself in the RasDialer component. I was under the assumption Windows would handle connecting to pre-requisites for me.

Apr 22, 2009 at 5:37 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.