از RasAPI32 استفاده کنید.
[System.Runtime.InteropServices.DllImport(
"rasapi32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern System.UInt32 RasDial(
[System.Runtime.InteropServices.In] RasDialExtensions lpRasDialExtensions,
[System.Runtime.InteropServices.In] System.String lpszPhonebook,
[System.Runtime.InteropServices.In] RasDialParams lpRasDialParams,
System.UInt32 dwNotifierType,
System.Delegate lpvNotifier,
ref System.IntPtr lphRasConn
);
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Sequenti al,
CharSet = System.Runtime.InteropServices.CharSet.Auto)]
internal class RasDialParams
{
public System.Int32 dwSize =
System.Runtime.InteropServices.Marshal.SizeOf(type of(RasDialParams));
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = RAS_MaxEntryName + 1)]
public System.String szEntryName = null;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = RAS_MaxPhoneNumber + 1)]
public System.String szPhoneNumber = null;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = RAS_MaxCallbackNumber + 1)]
public System.String szCallbackNumber = null;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = MaxUser + 1)]
public System.String szUserName = null;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = MaxPassword + 1)]
public System.String szPassword = null;
[System.Runtime.InteropServices.MarshalAs(
System.Runtime.InteropServices.UnmanagedType.ByVal TStr,
SizeConst = MaxDomain + 1)]
public System.String szDomain = null;
public System.Int32 dwSubEntry = 0;
public System.Int32 dwCallbackId = 0;
}
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Sequenti al)]
internal class RasDialExtensions
{
public readonly System.Int32 dwSize =
System.Runtime.InteropServices.Marshal.SizeOf(type of(RasDialExtensions));
public System.UInt32 dwfOptions = 0;
public System.Int32 hwndParent = 0;
public System.Int32 reserved = 0;
public System.Int32 reserved1 = 0;
public RasEapInfo RasEapInfo = new RasEapInfo();
}
public void Connect()
{
// Define the dial parameters
RasDialParams parms = new RasDialParams();
parms.szDomain = this.Domain;
parms.szUserName = this.UserName;
parms.szPassword = this.Password;
parms.szEntryName = this.PhonebookEntry;
System.UInt32 retVal =
RasDial(null, null, dialParms, 0, null, ref RasConnectionHandle);
}
http://www.eggheadcafe.com/community...plication.aspx
http://social.msdn.microsoft.com/for...c-c3a3efa5ceb6