I also saw it on the Internet. There is nothing to say. Read the Code directly:
Using system; using system. runtime. interopservices; public struct rasconn {public int dwsize; Public intptr hrasconn; [financialas (unmanagedtype. byvaltstr, sizeconst = 257)] Public String szentryname; [financialas (unmanagedtype. byvaltstr, sizeconst = 17)] Public String szdevicetype; [financialas (unmanagedtype. byvaltstr, sizeconst = 129)] Public String szdevicename;} [structlayout (layoutkind. sequential, charset = charset. AUT O)] public struct rasstats {public int dwsize; Public int dwbytesxmited; Public int dwbytesrcved; Public int dwframesxmited; Public int unknown; Public int dwcrcerr; Public int dwtimeouterr; Public int unknown; public int dwhardwareoverrunerr; Public int dwframingerr; Public int dwbufferoverrunerr; Public int dwcompressionratioin; Public int dwcompressionratioout; Public int dwbps; Public int dwconne Ctionduration;} [structlayout (layoutkind. sequential, charset = charset. auto)] public struct rasentryname {public int dwsize; // [financialas (unmanagedtype. byvaltstr, sizeconst = (INT) rasfieldsizeconstants. ras_maxentryname + 1)] Public String szentryname; // # If winver5 // public int dwflags; // [financialas (unmanagedtype. byvaltstr, sizeconst = 260 + 1)] // Public String szphonebookpath; // # endif} public class Ras {[dllimport ("Rasapi32.dll", entrypoint = "rasenumconnectionsa", setlasterror = true)] internal static extern int rasenumconnections (ref rasconn lprasconn, // buffer to receive connections dataref int lpcb, // size in bytes of bufferref int lpcconnections // Number of connections written to buffer); [dllimport ("rasapi32.dll", charset = charset. auto)] internal static extern uint rasgetconnectionstatistics (intptr hrasconn, // Handle to the connection [In, out] rasstats lpstatistics // buffer to receive statistics); [dllimport ("rasapi32.dll", charset = charset. auto)] public extern static uint rashangup (intptr hrasconn // handle to the RAS connection to hang up); [dllimport ("rasapi32.dll", charset = charset. auto)] public extern static uint rasenumentries (string reserved, // reserved, must be nullstring lpszphonebook, // pointer To full path and // file name of phone-Book File [In, out] rasentryname [] lprasentryname, // buffer to receive // phone-book entriesref int lpcb, // size in bytes of bufferout int lpcentries // number of entries written // to buffer); [dllimport ("wininet. DLL ", charset = charset. auto)] public extern static int internetdial (intptr hwnd, [in] string lpszconnectoid, uint dwflags, ref int lpdwconnection, uint dwreser Ved); Public RAS () {}} public Enum del_cache_type // type to be deleted. {File, // indicates a Temporary Internet File cookie // indicates a cookie}; public class rasdisplay {[dllimport ("wininet. DLL ", charset = charset. auto)] public static extern bool deleteurlcacheentry (del_cache_type type); Private string m_duration; private string m_connectionname; private string [] m_connectionnames; private double m_tx; private double m_rx; private bool m_connected; private intptr m_connectedrashandle; rasstats status = new rassta TS (); Public rasdisplay () {m_connected = true; Ras lpras = new RAS (); rasconn lprasconn = new rasconn (); lprasconn. dwsize = marshal. sizeof (typeof (rasconn); lprasconn. hrasconn = intptr. zero; int lpcb = 0; int lpcconnections = 0; int nret = 0; lpcb = marshal. sizeof (typeof (rasconn); nret = Ras. rasenumconnections (ref lprasconn, ref lpcb, reflpcconnections); If (nret! = 0) {m_connected = false; return;} If (lpcconnections> 0) {// For (INT I = 0; I <lpcconnections; I ++) // {rasstats stats = new rasstats (); m_connectedrashandle = lprasconn. hrasconn; Ras. rasgetconnectionstatistics (lprasconn. hrasconn, stats); m_connectionname = lprasconn. szentryname; int hours = 0; int minutes = 0; int seconds = 0; hours = (stats. dwconnectionduration/1000)/3600); minutes = (stats. dwconnection Duration/1000)/60)-(hours * 60); seconds = (stats. dwconnectionduration/1000)-(minutes * 60)-(hours * 3600); m_duration = hours + "hours" + minutes + "Minutes" + seconds + "secs "; m_tx = stats. dwbytesxmited; m_rx = stats. dwbytesrcved; //} else {m_connected = false;} int lpnames = 1; int entrynamesize = 0; int lpsize = 0; rasentryname [] names = NULL; entrynamesize = marshal. sizeof (typeof (rasentry Name); lpsize = lpnames * entrynamesize; names = new rasentryname [lpnames]; names [0]. dwsize = entrynamesize; uint retval = Ras. rasenumentries (null, null, names, ref lpsize, out lpnames); // if we have more than one connection, we need to do it againif (lpnames> 1) {names = new rasentryname [lpnames]; for (INT I = 0; I <names. length; ++ I) {Names [I]. dwsize = entrynamesize;} retval = Ras. rasenumentries (null, null, names, ref lpsiz E, out lpnames);} m_connectionnames = new string [names. length]; If (lpnames> 0) {for (INT I = 0; I <m_connectionnames.length; ++ I) {m_connectionnames [I] = Names [I]. szentryname ;}} Public String duration {get {return m_connected? M_duration: "" ;}} Public String [] connections {get {return m_connectionnames;} public double bytestransmitted {get {return m_connected? M_tx: 0 ;}} public double bytesreceived {get {return m_connected? M_rx: 0 ;}} Public String connectionname {get {return m_connected? M_connectionname: "" ;}} public bool isconnected {get {return m_connected;} public int connect (string connection) {int temp = 0; uint internet_auto_dial_unattended = 2; int retval = Ras. internetdial (intptr. zero, connection, internet_auto_dial_unattended, ref temp, 0); Return retval;} public void disconnect () {ras. rashangup (m_connectedrashandle );}}
Usage:
RASDisplay ras = new RASDisplay();
ras.Disconnect();
int val = ras.Connect( "ADSL" );
"ADSL" name is not limited. If Val returns 0, it indicates that the number has been successfully drawn.