J
Juan Gabriel Del Cid
In C#, what is the best way to detect whether a network
Use WMI, like so:
using System;
using System.Management;
using System.Windows.Forms;
namespace Tests {
public class NetworkProbe {
public static void Main(string []args) {
ObjectQuery objectQuery = new ObjectQuery(
"select * from Win32_NetworkAdapter " +
"where NetConnectionStatus=2"); // 2 means connected
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
int connectedNetworks = searcher.Get().Count;
if (connectedNetworks > 0) {
Console.WriteLine("There are {0} connected network interfaces",
connectedNetworks);
} else {
Console.WriteLine("There is no network connection present");
}
}
}
}
That should do it,
-JG
connection is present?
Use WMI, like so:
using System;
using System.Management;
using System.Windows.Forms;
namespace Tests {
public class NetworkProbe {
public static void Main(string []args) {
ObjectQuery objectQuery = new ObjectQuery(
"select * from Win32_NetworkAdapter " +
"where NetConnectionStatus=2"); // 2 means connected
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
int connectedNetworks = searcher.Get().Count;
if (connectedNetworks > 0) {
Console.WriteLine("There are {0} connected network interfaces",
connectedNetworks);
} else {
Console.WriteLine("There is no network connection present");
}
}
}
}
That should do it,
-JG