Computer Online ?

  • Thread starter Thread starter RS
  • Start date Start date
There are two way that come to mind

//Using WinAPI - make sure you use Runtime.Interopservices


[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out Description,
int ReservedValue ) ;

public static bool IsConnected( )
{

int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;

}



or this way...
 
Two come to mind

Dim webRequestor As HttpWebRequest

Dim webResponder As HttpWebResponse

Dim url As String = ConfigurationSettings.AppSettings.Item("url").ToString

Try

webRequestor = CType(WebRequest.Create(url), System.Net.HttpWebRequest)

webResponder = CType(webRequestor.GetResponse, System.Net.HttpWebResponse)

If webResponder.StatusCode = HttpStatusCode.OK Then

Return True

Or using the winAPI

Make sure you include Runtime.InteropServices;

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out Description,
int ReservedValue ) ;

//Creating a function that uses the API function...
public static bool IsConnected( )
{

int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;

}
 
Hi William,

Thanks for that. I've wondered myself.

MSDN says that InternetGetConnectedState() will tell me whether there's a
(default) connection or not. Do you know how I can tell more, eg, what's
flowing on it - ie, whether there's an incoming stream or anything outgoing
from other applications ?

Thanks,
Fergus
 
Back
Top