Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dial up a connection to internet with C#

50 views
Skip to first unread message

Cyril Tisseron

unread,
Nov 28, 2002, 11:43:50 AM11/28/02
to
Hi all of you

Are there any object to manage dial up connection with C#?

I would like to get the list of the existing connection on my system.
I know that I can get its in the registry but, I don't know how to run the
dialup.
I'm sure that there is object but I don't know which.

Thanks by advance.

Cyril


Lion Shi

unread,
Nov 29, 2002, 2:49:13 AM11/29/02
to
Hello Henrik,

I am afraid there is not such a class in.NET Framework. You can use the RAS
APIs in the Rasapi32.dll via PInvoke. I have found a sample code from one
of the old posts (titled "Dial A connection" in
microsoft.public.dotnet.languages.csharp). For you convenience, I have
included it here.

I hope this is helpful.

/***************************************************************************
*
using System;
using System.Runtime.InteropServices;

namespace RAS
{
public class RasManager
{
public const int RAS_MaxEntryName = 256;
public const int RAS_MaxPhoneNumber = 128;
public const int UNLEN = 256;
public const int PWLEN = 256;
public const int DNLEN = 15;
public const int MAX_PATH = 260;
public const int RAS_MaxDeviceType = 16;
public const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;

public delegate void Callback(uint unMsg, int rasconnstate, int dwError);

[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)]
public struct RASDIALPARAMS
{
public int dwSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxEntryName + 1)]
public string szEntryName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxCallbackNumber+ 1)]
public string szCallbackNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=UNLEN + 1)]
public string szUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=PWLEN + 1)]
public string szPassword;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=DNLEN + 1)]
public string szDomain;
public int dwSubEntry;
public int dwCallbackId;
}

[DllImport("rasapi32.dll", CharSet=CharSet.Auto)]
public static extern int RasDial (int lpRasDialExtensions, string
lpszPhonebook,
ref RASDIALPARAMS lprasdialparams, int dwNotifierType,
Callback lpvNotifier, ref int lphRasConn);

private RASDIALPARAMS RasDialParams;
private int Connection;

public RasManager()
{
Connection = 0;
RasDialParams = new RASDIALPARAMS();
RasDialParams.dwSize = Marshal.SizeOf(RasDialParams);
}

#region Properties
public string UserName
{
get
{
return RasDialParams.szUserName;
}
set
{
RasDialParams.szUserName = value;
}
}

public string Password
{
get
{
return RasDialParams.szPassword;
}
set
{
RasDialParams.szPassword = value;
}
}

public string EntryName
{
get
{
return RasDialParams.szEntryName;
}
set
{
RasDialParams.szEntryName = value;
}
}
#endregion

public int Connect()
{
Callback rasDialFunc = new Callback(RasManager.RasDialFunc);
RasDialParams.szEntryName += "\0";
RasDialParams.szUserName += "\0";
RasDialParams.szPassword += "\0";
int result = RasDial (0, null, ref RasDialParams, 0, rasDialFunc, ref
Connection);
return result;
}

public static void RasDialFunc(uint unMsg, int rasconnstate, int dwError)
{
}
}
}

An example of establishing a connection:

RasManager myRas = new RasManager();
myRas.EntryName = "MyPhonebook entry"; //
entryname in phonebook
myRas.UserName = "username";
myRas.Password = "password";
myRas.Connect().ToString();

/***************************************************************************
*******

Best regards,

Lion Shi [MS]
MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
From: "Cyril Tisseron" <c...@gplsysteme.com>
Subject: Dial up a connection to internet with C#
Date: Thu, 28 Nov 2002 17:43:50 +0100
Lines: 14
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <eKGVK4vlCHA.2116@tkmsftngp07>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: gpls.net2.nerim.net 62.4.19.8
Path: cpmsftngxa09!cpmsftngxa10!tkmsftngp01!tkmsftngp07
Xref: cpmsftngxa09 microsoft.public.dotnet.languages.csharp:112171
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

0 new messages