using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Threading; using System.ComponentModel;
namespace mainApp ...{ class RASHelper ...{ constint INTERNET_RAS_INSTALLED =0x10;
[DllImport("WININET", CharSet = CharSet.Auto)] publicstaticexternbool InternetGetConnectedState( refint lpdwFlags, int dwReserved);
//create array of structures to pass to API int ret; int conns =0; RASCONN[] rarr =new RASCONN[256]; rarr.Initialize(); rarr[0].dwSize = Marshal.SizeOf(typeof(RASCONN)); int lr = rarr[0].dwSize * rarr.Length;
//call RasEnumConnections to loop all RAS connections ret = RasEnumConnections(rarr, ref lr, ref conns); if (ret !=0) thrownew Win32Exception(ret); //loop through each RASCONN struct for (int i =0; i < conns; i++) ...{ //retrieve RASCONN struct RASCONN r = rarr[i];
//if connection bad, handle will be 0 if (r.hrasconn == IntPtr.Zero) continue; RasHangUp(r.hrasconn);