Siamo collegati ad una rete?
// Windows 2000
using System.Management;
...
private bool IsNetworkAlive2000()
{
    bool Result = false;
    ManagementClass mc  = new ManagementClass( @"root\WMI", @"MSNdis_MediaConnectStatus", null );
    ManagementObjectCollection moc = mc.GetInstances();
    foreach( ManagementObject mo in moc )
    {
        uint status = (uint) mo["NdisMediaConnectStatus"];
        Result = (status == 0)?true:Result;
    }
    return Result;
}
// Windows XP
using System.Management;
...
private bool IsNetworkAliveXP()
{
    bool Result = false;
    ManagementClass mc  = new ManagementClass( @"Win32_NetworkAdapter" );
    ManagementObjectCollection moc = mc.GetInstances();
    foreach( ManagementObject mo in moc )
    {
        object val = mo["NetConnectionStatus"];
        Result = (val == null || ((ushort)val) != 2)?Result:true;
    }
    return Result;
}
// Windows NT (Testato) e Win 95/98/ME (Non testati)
using System.Runtime.InteropServices;
...
[DllImport("sensapi.dll")]
private static extern bool IsNetworkAlive( out int flags );
private bool IsNetworkAliveNT()
{
    int flags;
    return IsNetworkAlive(out flags);
}
Fonte: microsoft.public.dotnet.general
powered by IMHO 1.1 with Emoticon Formatter