I would like to disable the network adapter if no internet connection is present so my cell data modem will connect to send alerts if the cable is cut or power is out. Found some code but it will not run probably because it needs some includes or uses data. Also I need a ping statement if possible.
METHOD 1
Process.Start("cmd.exe","/c netsh interface set interface 'Local Area Connection' DISABLED");
METHOD 2
Must declare System.Management
SelectQuery wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId != NULL");
ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(wmiQuery);
foreach (ManagementObject item in searchProcedure.Get())
{
if (((string)item["NetConnectionId"]) == "Local Network Connection")
{
item.InvokeMethod("Disable", null);
}
}