Compact Framework - open/close VPN-connection by code

Asked By Oliver Brings on 05-Jan-07 04:40 AM
hi, i am looking for a possibility to open/close an already defined vpn-connection by code (c#, dotnet-cf2.0) on a 'windows mobile 5.0'-device. has anybody already found a way to do this? thanks a lot! regards, oliver
Sushila Patel replied to Oliver Brings on 05-Jan-07 10:25 AM

Check if this code helps

http://www.codeproject.com/vb/net/SimpleLineTester.asp?df=100&forumid=48025&exp=0&select=1613897

It tests the availability of a VPN-Connection over more then 24 hours

There is one solution given in thread which discusses about starting a
VPN from code using a RAS connection (IntelliProg components used)

http://groups.google.co.uk/group/microsoft.public.pocketpc.developer.networking/browse_thread/thread/c5e2c7c81e814cac/2f75c6ca5df4e62f?lnk=raot&hl=en

http://www.pcreview.co.uk/forums/thread-2187690.php

Mohamed replied to Sushila Patel on 28-Jul-10 09:40 AM

using System;

using System.Collections.Generic;
using System.Text;
using OpenNETCF.Net;
namespace Example{
    class VPN
    {
      public Boolean connect()
      {
        try
        {
          ConnectionManager NetCon = new ConnectionManager();
          ConnectionDetailCollection NetConDetColl = NetCon.GetConnectionDetailItems() ;
          ConnectionDetail NetConDet = null;
          foreach (ConnectionDetail cd in NetConDetColl)
          {
            if ((cd.ConnectionType == ConnectionType.VPN) &&
            (cd.ConnectionSubType == ConnectionSubType.PPTP))
            {
              NetConDet = cd;
              break;
            }
          }

          if (NetConDet == null)
            throw new Exception("No VPN network configured");

          NetCon.Connect(NetConDet.DestinatonNetwork, true,
          ConnectionMode.Synchronous);// Asynchronous);

          return true;
        }
        catch(Exception ex)
        {
          return false;
        }
        finally
        {

        }

      }
    }
   
}

Yoc replied to Oliver Brings on 06-Jan-11 06:56 AM
It was helped very much. Thank you.

from Japan